kiotoqq wrote > I want to add a shorter column to my dataset with the function "merge", > it > should be filled with NAs wo be as long as the other colums, like this: > > id age > 9 46 > 8 56 > 6 52 > 5 NA > 4 NA > 3 NA > 1 NA > > i did this: > pa1 <- merge(pa1, an1, by="mergeid") > > and it says "'by' must specify uniquely valid column(s)"
how about ... #Data d1<-data.frame(id=c(9,8,6,4,4,3,1)) d2<-data.frame(id=c(9,8,6),age=c(46,56,52)) # Left Merge d<-merge(d1,d2,all.x=TRUE) # Reorder d[order(d$id,decreasing=TRUE),] HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/how-to-add-a-column-from-another-dataset-with-merge-tp4652482p4652486.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org 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.