我希望下面的代码: transform cars
in a tbl_df then 排除所有以“variable”开头的列;因此基本上返回 cars
tbl_df(cars) %>%
select(-starts_with("variable"))
有什么方法可以调整此函数以检索汽车而不是空数据集?
我之所以要执行这个显然毫无意义的操作,是因为该函数嵌套在一个循环中,其中以 variable
开头的列可能存在也可能不存在。
最佳答案
也许通过在表达式的前面提到所有可能的列:
tbl_df(cars) %>% select(1:ncol(.), -starts_with("variable"))
关于r - 当没有匹配项时,如何防止 select() 检索空数据框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37330512/