Hello all, I would like to take a data frame such as the following one:
> df <- data.frame(id=c("A","A","B","B"),first=c("BX",NA,NA,"LF"),second=c(NA,"TD","BZ",NA),third=c(NA,NA,"RB","BT"),fourth=c("LG","QR",NA,NA)) > df id first second third fourth 1 A BX <NA> <NA> LG 2 A <NA> TD <NA> QR 3 B <NA> BZ RB <NA> 4 B LF <NA> BT <NA> and merge rows based on the id, such that the value in the column will be one of four possibilities: if both values in the original df are <NA>, the new value should also be <NA>. If there are two non-NA values, then the new value should read "clash". Otherwise, the new value should be whichever value was not <NA>. An example output from the command would read in df and read out: id first second third fourth 1 A BX TD <NA> clash 2 B LF BZ clash <NA> I'd be grateful if someone could point me in the right direction. Thanks, Jonathan [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.