使用列名选择data.table中列的多个范围 [英] select multiple ranges of columns in data.table using column names
本文介绍了使用列名选择data.table中列的多个范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用像 c(1:5,27:30)
这样的数字矢量在data.table中选择列的多个范围。 。有什么办法可以对列名做同样的事情?例如,采用类似于 col1:col5,col27:col30
?
I can select multiple ranges of columns in a data.table using a numeric vector like c(1:5,27:30)
. Is there any way to do the same with column names? For example, in some form similar to col1:col5,col27:col30
?
推荐答案
您可以使用 dplyr
:
df <- data.frame(a=1, b=2, c=3, d=4, e=5, f=6, g=7)
dplyr::select(df, a:c, f:g)
a b c f g
1 2 3 6 7
这篇关于使用列名选择data.table中列的多个范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文