[R] df manipulation

Uwe Ligges ligges at statistik.uni-dortmund.de
Thu Jul 19 15:08:35 CEST 2007



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 "NA"s.

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 at 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.



More information about the R-help mailing list