【发布时间】:2017-02-22 17:53:22
【问题描述】:
library(tidyverse)
data(mtcars)
mtcars <- rownames_to_column(mtcars,var = "car")
mtcars$id <- c(1:length(mtcars$car))
mtcars$make <- map_chr(mtcars$car,~strsplit(.x," ")[[1]][1])
mt2 <- mtcars %>% select(1:4,id,make) %>% nest(-make,.key = "l")
mt4 <- mt2[1:5,]
mt5 <- mt2[1:5,]
`
现在 - 我想将马自达的 listcolumn 设置为 NULL。
mt4[mt4$make=="Mazda","l"]<-NULL
但是,比较mt4$l 和mt5$l,我发现“mazda”元素已被删除,但其他元素已向上移动。
有人可以解释为什么这是合乎逻辑的吗?
如何选择性地仅 NULL 列表列中的某个元素?
【问题讨论】:
-
请务必在您的示例代码中包含非基础包。