Re: [R] df manipulation
Hi, see below: df index value 1 1 1 2 4 6 3 7 4 4 9 5 511 3 613 2 foo - function(x){ + index - ifelse(x %in% df$index, df$value[which(df$index %in% x)], NA) + return(index) + } df_ok - data.frame(index=1:13, value=sapply(1:13, foo)) df_ok index value 1 1 1 2 2NA 3 3NA 4 4 6 5 5NA 6 6NA 7 7 4 8 8NA 9 9 5 1010NA 1111 3 1212NA 1313 2 -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O On 19/07/07, Nikola Markov [EMAIL PROTECTED] wrote: I have multicolumn data.frames with the first comumn giving ordinal observation index ( ex.: 1 4 7 9 11 13 etc). I would like to fill up the missing observations (i.e. 2 3 5 6 8 etc) with NAs. Thank you __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] df manipulation
Nikola Markov wrote: I have multicolumn data.frames with the first comumn giving ordinal observation index ( ex.: 1 4 7 9 11 13 etc). I would like to fill up the missing observations (i.e. 2 3 5 6 8 etc) with NAs. Please specify reproducible examples, they make it much easier to help! If you have: df - data.frame(index = c(1, 4, 7), x1 = 1:3, x2 = 3:1) df Then you can say: temp - data.frame(index = 1:max(df$index)) df - merge(temp, df, all.x = TRUE) df Uwe Ligges Thank you __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.