0
我有這樣的數據集:刪除「細胞」與NA和列
df<- structure(list(p1 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA), p2 = structure(c(NA, NA, 5L, 6L,
NA, 2L, 7L, NA, NA, 4L, NA, 3L, NA, 1L, 1L, 1L, 1L), .Label = c("",
"R16", "R29", "R3", "R36", "R40", "R56"), class = "factor"),
p3 = structure(c(NA, 1L, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA), .Label = "R33", class = "factor")), .Names = c("p1",
"p2", "p3"), class = "data.frame", row.names = c(NA, -17L))
我想刪除「細胞」不包含吶行。
我嘗試這樣做:
na.omit(df)
但這不是工作,我猜是因爲它是整行。
如何從細胞中去除NA而不是整行?
輸出示例:
p2 p3
R36 R33
R40
R16
R56
R3
R29
爲什麼要刪除'NA'?無論如何,如果你想要推斷空字符值,你可以這樣做:''df [is.na(df)] < - 「」' – Jaap
也許你想要做'lapply(as.list(df),function(x) x [!is.na(x)])' –
@amatsuo_net,抱歉,我在發佈我的答案後看到了您的評論。常識走向同一個方向。 –