假设我有一个列表 v
> v[1:5]
[1] A1CF A2M A2M AADAC AADACL3
如果我尝试创建一个新列表
x=c(v[1],v[2])
我明白了
> x
[1] 1 2
为什么 R 将整数值分配给 x,以及如何将字符串分配给新列表 x?
假设我有一个列表 v
> v[1:5]
[1] A1CF A2M A2M AADAC AADACL3
如果我尝试创建一个新列表
x=c(v[1],v[2])
我明白了
> x
[1] 1 2
为什么 R 将整数值分配给 x,以及如何将字符串分配给新列表 x?
It seems that v
is a vector of factors.
> v <- factor(c("A1CF", "A2M", "A2M", "AADAC", "AADACL3"))
> c(v[1],v[2]) # this reproduces your problem
[1] 1 2
>
> # possible alternatives. This solves your problem
> factor(c(levels(v)[1], levels(v)[2])) # Alternative 1
[1] A1CF A2M
Levels: A1CF A2M
> factor(levels(v)[1:2]) # Alternative 2
[1] A1CF A2M
Levels: A1CF A2M
Btw, you are dealing with a vector, not with a list.