How do I add a vector as a row to an existing data frame when the vector is longer than the data frame

时间:2015-07-08 15:55:06

标签: r

Apologies for a probably basic question but I can't seem to work out how to get this to work...

I want to add a row vector to an existing data frame. However, often the new row will have more columns than the existing data frame and I would like to fill the missing column entries with NA or blank strings.

For example, using this set up:

existing <- data.frame(rbind(letters[1:5], letters[6:10]))
new_row <- letters[20:26]

I would like to end up with the following:

a  b  c  d  e  ""  ""
f  g  h  i  j  ""  ""
t  u  v  w  x  y   z

The rbind function only accept equal width vectors. I have heard of rbind.fill from the plyr package but this only works for two data frames. Does anyone have a simple way to do this?

Many thanks Adrian

0 个答案:

没有答案