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
RICHARD M. HEIBERGER
2010-Jul-26 00:07 UTC
[R] Is there a function to interdigitate two columns?
> result <- data.frame(samp=samp, merged=ifelse(is.na(student2), student1,student2))> resultsamp merged 1 A 25.50 2 B 29.40 3 C 22.00 4 D 34.30 5 E 13.60 6 F 10.50 7 G 19.70 8 H 20.22 9 I 17.00 10 J 12.90>Rich [[alternative HTML version deleted]]