[英]subsetting columns of a tibble with a character vector from another tibble
我有兩個小題詞
>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
我想使用names <- select(a.tibble,names)
來子集b.tibble
以使c.tibble
:
>c.tibble
a c d
1 1 1
1 1 1
我的子集是非常重要names
,因為在現實中我有很多名稱子集大tibble。 這樣一來,通常的select(b.tibble,-c(b,e))
或其他“手動”列名稱的輸入就不可能了。
數據
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.