Skip to content
Prev 70750 / 398525 Next

Add Columns and Order for Rbind?

On 5/31/05, khobson at fd9ns01.okladot.state.ok.us
<khobson at fd9ns01.okladot.state.ok.us> wrote:
Suppose we have this test data:

# test data
irish <- head(iris)
one.row <- data.frame(Sepal.Length = 5, Sepal.Area = 10)

# Then we rbind an NA row to irish and fill it with one.row

irish <- rbind(irish, NA)
irish[nrow(irish),names(one.row)] <- one.row


# If you don't want columns added to the master list do this instead:

irish <- head(iris)  # recreate test data
irish  <- rbind(irish, NA)
both <- intersect(names(irish), names(one.row))
irish[nrow(irish), both] <- one.row[,both]

Note that appending rows one at a time can be slow.