从 R 中 table 中的频率值制作矢量
Making vector from frequency values in a table in R
我有一个字符向量
helloWorld <- c("H", "e", "l", "l", "o", " ",
"W", "o", "r", "l", "d", "!")
我从中得到一个table的字符频率
frequency = table(helloWorld)
给出:
> frequency
helloWorld
! d e H l o r W
1 1 1 1 1 3 2 1 1
现在我想创建一个向量,其值为:
[1] 1 1 1 1 1 3 2 1 1
我的意思是我只想用频率值制作一个矢量 v
。我怎么可能那样做?
您可以使用 as.vector()
删除 table 的所有属性
as.vector(table(helloWorld))
# [1] 1 1 1 1 1 3 2 1 1
或者(大约快两倍),将 helloWorld
转换为因子并使用 tabulate()
tabulate(factor(helloWorld))
# [1] 1 1 1 1 1 3 2 1 1
我有一个字符向量
helloWorld <- c("H", "e", "l", "l", "o", " ",
"W", "o", "r", "l", "d", "!")
我从中得到一个table的字符频率
frequency = table(helloWorld)
给出:
> frequency
helloWorld
! d e H l o r W
1 1 1 1 1 3 2 1 1
现在我想创建一个向量,其值为:
[1] 1 1 1 1 1 3 2 1 1
我的意思是我只想用频率值制作一个矢量 v
。我怎么可能那样做?
您可以使用 as.vector()
as.vector(table(helloWorld))
# [1] 1 1 1 1 1 3 2 1 1
或者(大约快两倍),将 helloWorld
转换为因子并使用 tabulate()
tabulate(factor(helloWorld))
# [1] 1 1 1 1 1 3 2 1 1