我想将因子的值转换为列表,我该怎么做?PS:对不起,我是 R 新手
示例:我有以下因素:
> table(v)
v
(0,80] (80,500] (500,1000] (1000,10000] (10000,90000]
8259 2167 112 62 1
我怎样才能得到:
c(8259,2167,112,62,1)
我想将因子的值转换为列表,我该怎么做?PS:对不起,我是 R 新手
示例:我有以下因素:
> table(v)
v
(0,80] (80,500] (500,1000] (1000,10000] (10000,90000]
8259 2167 112 62 1
我怎样才能得到:
c(8259,2167,112,62,1)
使用unname()
:
x <- table(cut(runif(100), 5))
x
(0.00448,0.202] (0.202,0.399] (0.399,0.596] (0.596,0.794]
24 23 16 19
(0.794,0.991]
18
unname(x)
[1] 24 23 16 19 18
您可以将 table 的结果转换为 data.frame 并且:
as.data.frame(x)$Freq
[1] 28 13 20 20 19
或者:
test <- as.vector(table(v)[])
test