将df中的字符替换为R中的数字向量

将df中的字符替换为R中的数字向量,r,bioinformatics,R,Bioinformatics,我想用数字向量替换字符 我有这个df: First Second Third A C D F R K and I also have vectors like these A = c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) R = c(0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) N = c(0

我想用数字向量替换字符

我有这个df:

First Second Third
 A      C      D
 F      R      K

and I also have vectors like these
A = c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)

R = c(0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)

N = c(0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)

我试了好几次,但都做不到。有人有什么建议或想法吗?

一个选项是
取消列出
(如果是
因子
,则转换为
字符
),然后使用
mget
列表中返回该对象的值

lst1 <- mget(as.character(unlist(df)))

lst1你能分享你尝试过的代码吗?例如:df$
First
[df$
First
==“A”]我用过这个q[q==“A”]@ManuelDominguezBecerra你可以做
df[]