Adding row to a data frame with missing values

后端 未结 2 594
别那么骄傲
别那么骄傲 2020-12-19 03:22

So I have this data frame

df <- data.frame( A=1:10, B=LETTERS[1:10], C=letters[1:10], stringsAsFactors= F )

I want to add a row to this

2条回答
  •  隐瞒了意图╮
    2020-12-19 04:02

    Here's an alternative base version that preserves the datatypes.

    new.row <- head(df[NA,], 1)
    new.row[c('A', 'B')] <- list(A=11, B='K')
    rbind(df, new.row)
    

提交回复
热议问题