r-faq

Simultaneously merge multiple data.frames in a list

微笑、不失礼 提交于 2021-02-17 07:04:54
问题 I have a list of many data.frames that I want to merge. The issue here is that each data.frame differs in terms of the number of rows and columns, but they all share the key variables (which I've called "var1" and "var2" in the code below). If the data.frames were identical in terms of columns, I could merely rbind , for which plyr's rbind.fill would do the job, but that's not the case with these data. Because the merge command only works on 2 data.frames, I turned to the Internet for ideas.

Simultaneously merge multiple data.frames in a list

假如想象 提交于 2021-02-17 07:04:31
问题 I have a list of many data.frames that I want to merge. The issue here is that each data.frame differs in terms of the number of rows and columns, but they all share the key variables (which I've called "var1" and "var2" in the code below). If the data.frames were identical in terms of columns, I could merely rbind , for which plyr's rbind.fill would do the job, but that's not the case with these data. Because the merge command only works on 2 data.frames, I turned to the Internet for ideas.

Transpose / reshape dataframe without “timevar” from long to wide format

早过忘川 提交于 2021-02-05 09:29:21
问题 I have a data frame that follows the below long Pattern: Name MedName Name1 atenolol 25mg Name1 aspirin 81mg Name1 sildenafil 100mg Name2 atenolol 50mg Name2 enalapril 20mg And would like to get below (I do not care if I can get the columns to be named this way, just want the data in this format): Name medication1 medication2 medication3 Name1 atenolol 25mg aspirin 81mg sildenafil 100mg Name2 atenolol 50mg enalapril 20mg NA Through this very site I have become familiarish with the reshape

Transpose / reshape dataframe without “timevar” from long to wide format

我怕爱的太早我们不能终老 提交于 2021-02-05 09:29:20
问题 I have a data frame that follows the below long Pattern: Name MedName Name1 atenolol 25mg Name1 aspirin 81mg Name1 sildenafil 100mg Name2 atenolol 50mg Name2 enalapril 20mg And would like to get below (I do not care if I can get the columns to be named this way, just want the data in this format): Name medication1 medication2 medication3 Name1 atenolol 25mg aspirin 81mg sildenafil 100mg Name2 atenolol 50mg enalapril 20mg NA Through this very site I have become familiarish with the reshape

How to call an object with the character variable of the same name

旧时模样 提交于 2021-01-29 13:20:46
问题 I'm trying to write a function in R to batch-analyse a number of files in a similar manner. The files are of class ExpressionSetIllumina . I can make a character (string) vector with names of all files in the directory and load each of them: list = list.files() for (i in list[1]) { load(i) } This loads files correctly > ls() [1] "i" "list" "SSD.BA.vsn" > class(SSD.BA.vsn) [1] "ExpressionSetIllumina" attr(,"package") [1] "beadarray" What I want to do now is to use i (character string "SSD.BA

Convert integer to class Date

我的梦境 提交于 2020-07-24 09:15:03
问题 I have an integer which I want to convert to class Date . I assume I first need to convert it to a string, but how? My attempt: v <- 20081101 date <- as.Date(v, format("%Y%m%d")) Error in charToDate(x) : character string is not in a standard unambiguous format Using paste() works, but is that really the correct way to do the conversion? date <- as.Date(paste(v), format("%Y%m%d")) date [1] "2008-11-01" class(date) # [1] "Date" 回答1: as.character() would be the general way rather than use paste(

Convert integer to class Date

杀马特。学长 韩版系。学妹 提交于 2020-07-24 09:09:32
问题 I have an integer which I want to convert to class Date . I assume I first need to convert it to a string, but how? My attempt: v <- 20081101 date <- as.Date(v, format("%Y%m%d")) Error in charToDate(x) : character string is not in a standard unambiguous format Using paste() works, but is that really the correct way to do the conversion? date <- as.Date(paste(v), format("%Y%m%d")) date [1] "2008-11-01" class(date) # [1] "Date" 回答1: as.character() would be the general way rather than use paste(

How do I get a list of built-in data sets in R?

試著忘記壹切 提交于 2020-05-22 13:35:29
问题 Can someone please help how to get the list of built-in data sets and their dependency packages? 回答1: There are several ways to find the included datasets in R: 1: Using data() will give you a list of the datasets of all loaded packages (and not only the ones from the datasets package); the datasets are ordered by package 2: Using data(package = .packages(all.available = TRUE)) will give you a list of all datasets in the available packages on your computer (i.e. also the not-loaded ones) 3: