Re: [R] data frame formatting

2015-08-18 Thread boB Rudis
Here's one way in base R: 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)) new_df <- data.frame(do.call(rbind, by(df, df$id, functi

[R] data frame formatting

2015-08-18 Thread Jon BR
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 ABX LG 2 A TD