所以我有這個數據幀添加一行到數據幀與缺失值
df <- data.frame(A=1:10, B=LETTERS[1:10], C=letters[1:10], stringsAsFactors= F)
我想添加一行與A = 11和C =「K」這個數據幀,但我不」在C列上有信息。實際上,我不知道數據框中除了A和B之外還有其他哪些列。這些缺失的列應該有NA。我能想到的最好的是:
tmp <- rep(NA, ncol(df)) # Batman!
df <- rbind(df, tmp)
df[ nrow(df), "A" ] <- 11
df[ nrow(df), "B" ] <- "K"
有沒有更簡單的方法?
看看我添加到我的答案的新版本。我認爲那是最乾淨的。 – BrodieG