r - Character to vector in R
问题描述
I have 3 binary vectors.
a<-c(0,0,1,0)
b<-c(1,0,0,0)
c<-c(0,0,0,1)
I need to choose 2 out of 3 vectors and check whether they are subsets. I have used combn function as bellow:
> combination<-combn(letters[1:3], 2)
> combination
[,1] [,2] [,3]
[1,] "a" "a" "b"
[2,] "b" "c" "c"
But the problem is- all the elements in combination are characters. How can I connect these elements (which are letters) to the binary vector?
For example if I call combination[1,1]
I can get binary vector a (not "a").
解决方案
您可以使用get
按名称搜索对象。
get(combination[1,1])
#[1] 0 0 1 0
或mget
更多:
do.call(cbind, mget(combination[,1]))
# a b
#[1,] 0 1
#[2,] 0 0
#[3,] 1 0
#[4,] 0 0
推荐阅读
- google-app-engine - AttributeError:“资源”对象在谷歌应用引擎中没有属性“列表”
- python - Django admin 自定义选择 formfield 选择
- c# - 无法从视图中获取值
- java - 转换'ArrayList
' 到 Java 中的 'String[][]' - java - JTA 事务不会被提交或回滚——JBossTS、Arjuna
- java - 如何覆盖现有属性的@AdminPresentation [Broadleaf Commerce]
- reactjs - react-script 与第三方节点模块的兼容性问题
- ravendb4 - 我们如何在 RavenDB 4 中以编程方式创建 RavenETL 任务?
- json - 在不知道特定层名称的情况下循环嵌套 json 对象
- vue.js - TypeError: this.$refs.cropper.getCroppedCanvas 不是函数