[英]subsetting columns of a tibble with a character vector from another tibble
I have two tibbles 我有两个小题词
>a.tibble
names other
a 0
c 0
d 0
>b.tibble
a b c d e
1 1 1 1 1
1 1 1 1 1
I would like to use names <- select(a.tibble,names)
to subset b.tibble
to make c.tibble
: 我想使用
names <- select(a.tibble,names)
来子集b.tibble
以使c.tibble
:
>c.tibble
a c d
1 1 1
1 1 1
It is important that I subset by names
because in reality I have many names to subset a large tibble. 我的子集是非常重要
names
,因为在现实中我有很多名称子集大tibble。 This makes it so the usual select(b.tibble,-c(b,e))
or other "manual" entry of column names is not possible. 这样一来,通常的
select(b.tibble,-c(b,e))
或其他“手动”列名称的输入就不可能了。
Data 数据
library(tibble)
a.tibble = tibble(names = c("a","c","d"), other = 0)
b.tibble = tibble(a = rep(1,2), b = 1, c = 1, d = 1, e = 1)
@ytk有一个对我b.tibble[, names(b.tibble) %in% a.tibble$names]
的答案b.tibble[, names(b.tibble) %in% a.tibble$names]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.