[R] Is there a function to interdigitate two columns?
Bryan Hanson
hanson at depauw.edu
Mon Jul 26 02:01:45 CEST 2010
Hello List Inhabitants:
I don¹t know what this operation is called or if there is a function that
does it automatically, hence I seek your help!
If I divide a large data collection tasks between two students, and I have a
master list of samples, but one student records some of the values, and the
other student the remainder, I need to get the two sets of student
measurements into one column. Here¹s an example:
samp <- LETTERS[1:10] # sample names
student1 <- c(NA, NA, 22, 34.3, NA, 10.5, 19.7, 20.22, NA, 12.9)
student2 <- c(25.5,29.4, NA, NA, 13.6, NA, NA, NA, 17.0, NA)
merged <- c(25.5,29.4, 22, 34.3, 13.6, 10.5, 19.7, 20.22, 17.0, 12.9)
df1 <- data.frame(samp, student1)
df2 <- data.frame(samp, student2)
merge(df1, df2) # these don't quite do what I want
join(df1, df2) # in latest release of plyr
What I need is to take the two columns of student data and merge them into
one that contains a single value for each sample, that is, I want to
generate a 2-column data frame containing samp and merged as shown above
I can write a function to do this (maybe not a great one) but I'd like to
know if it already exists. Seems like it ought to be a common process, but
as I'm not sure what it's called I'm having trouble searching.
Thanks as always, Bryan
*************
Bryan Hanson
Acting Chair
Professor of Chemistry & Biochemistry
DePauw University, Greencastle IN USA
More information about the R-help
mailing list