[Solved] Join columns of the same data.frame

df <- setNames(data.frame(matrix(, nrow = 100, ncol = 2)), c(“V1”, “V2”)) df$V1 <- “a, b, c, d, e” df$V2 <- “b, c, a, b, e” df$V3 <- paste(df$V1, df$V2, sep = “, “) Hope this helps. solved Join columns of the same data.frame

[Solved] Get access to the elements of a list in R [closed]

as.numeric(res$mean) Will do the job. As per your comment, so Forecast is the actual forecast and it is not always just the mean. Consider the following example using a data set taken from here library(forecast) births <- scan(“http://robjhyndman.com/tsdldata/data/nybirths.dat”) birthstimeseries <- ts(births, frequency=12, start=c(1946,1)) fit <- auto.arima(birthstimeseries) res <- forecast(fit, 12) plot(res) As you can see … Read more

[Solved] Combine multiple paired data frames from two lists

Given the explanation of your problem, the following may work: # get all overlapping names bindNames <- intersect(names(ww), names(dd03)) # get a list of rbinded data.frames, keeping unique observations newList <- lapply(bindNames, function(i) unique(rbind(ww[[i]], dd03[[i]]))) If at this point, you want to append all of your data.frames into a single data.frame, you can once again … Read more

[Solved] Output left or right part of a matched string [closed]

Here are a couple ways to only keep the text that comes before your pattern, if it exists a <- “GCUGUGGAGAUAACUGCGC” b <- “CUGGCUGAGGUAGUAGUUUGUGCUGUUGGUCGGGUUGUGACAUUGCCCGCUGUGGAGAUAACUGCGCAAGC” strsplit(b, a)[[1]][1] sub(paste0(a, “.*$”), “”, b) Now, you just need to read the files into R and loop over each pattern. I’m not exactly sure what you are looking for, but … Read more

[Solved] How to put values to R Matrix cells?

Do this instead (add your labels to the data object, and then use geom_tile and then geom_text) gg <- ggplot(data = cbind(melted_cormat,ids, ages), aes(x=Var1, y=Var2, fill=value)) + scale_x_discrete(labels = ids ) + scale_y_discrete(labels = ids) gg + geom_raster( aes(fill=value)) + geom_text( aes(x=Var1, y=Var2, label = ages), color=”red”, size=3) This brings the needed data into the … Read more

[Solved] I don’t know R and I want to calculate Spearman correlation in R with a given alpha and want to know the p value [closed]

Spearman correlations can be produced with the corr.test() function from the psych package. To illustrate use of Spearman correlation with ranked data, we’ll create two ranked variables for the Motor Trend Cars data set, mtcars, install the psych package, and then run corr.test(). install.packages(“psych”) library(psych) # create a couple of rank variables with mtcars data … Read more

[Solved] Download files with specific extension from a website [closed]

library(stringr) # Get the context of the page thepage = readLines(‘https://data.giss.nasa.gov/impacts/agmipcf/agmerra/’) # Find the lines that contain the names for netcdf files nc4.lines <- grep(‘*.nc4’, thepage) # Subset the original dataset leaving only those lines thepage <- thepage[nc4.lines] #extract the file names str.loc <- str_locate(thepage,’A.*nc4?”‘) #substring file.list <- substring(thepage,str.loc[,1], str.loc[,2]-1) # download all files for … Read more

[Solved] How to convert country names from English to French with the countrycode package?

Converting to French country names is a feature (one of many) that was recently added to the countrycode package, and is in the currently available version (0.19) on CRAN with version 0.19 or higher installed and loaded, you can convert to French country names with a command like… countrycode(c(‘Germany’, ‘USA’), ‘country.name’, ‘country.name.fr’) which will return… … Read more

[Solved] Why does indexing into a list with list[n] instead of list[[n]] in R not do what you would expect? [duplicate]

Because in general l[n] returns a sublist (possibly of length one), whereas l[[n]] returns an element: > lfile[2] [[1]] [1] “file2.xls” # returns SUBLIST of length one, not n’th ELEMENT > lfile[[2]] [1] “file2.xls” # returns ELEMENT From R intro manual: 6.1 Lists: It is very important to distinguish Lst[[1]] from Lst[1]. ‘[[…]]’ is the … Read more

[Solved] how to count the numbers based on two columns

The table command does what you want: table(df$V1, df$V2, useNA = “ifany”) Table will work on all distinct values. If you want blanks “” to be equivalent to missing values NA, you need to make that change in your data: df[df == “”] = NA Similarly, if the 1 x or 2 x doesn’t matter, … Read more

[Solved] Multiple plots in R with time series

Based on your comments you might be looking for: library(tidyverse) plot1 <- df %>% gather(key = measure, value = value, -year) %>% ggplot(aes(x = year, y = value, color = measure))+ geom_point()+ geom_line()+ facet_wrap(~measure) plot1 The biggest points here are gather and facet_wrap. I recommend the following two links: https://ggplot2.tidyverse.org/reference/facet_grid.html https://ggplot2.tidyverse.org/reference/facet_wrap.html solved Multiple plots in … Read more