I've got the following situation in R:
我在R中遇到以下情况:
> wordfreq
filiaalnummer filiaal type omschrijving filiaalnaam
1 3 3 2 1
> names(wordfreq)
[1] "filiaalnummer" "filiaal" "type" "omschrijving"
[5] "filiaalnaam"
> as.numeric(wordfreq)
[1] 1 3 3 2 1
Where each time the number represents the frequency of the word above. I would like to paste the names of the vector into one element with the correct frequency, so I would like to get the following:
每次数字代表上述单词的频率。我想将矢量的名称粘贴到一个具有正确频率的元素中,所以我想得到以下内容:
filiaalnummer filiaal filiaal filiaal filiaal type type type omschrijving omschrijving filiaalnaam
1 个解决方案
#1
Try this:
rep(names(wordfreq), times = wordfreq)
Here is a reproducible example:
这是一个可重复的例子:
wordfreq = sample.int(10, 5, replace = TRUE)
names(wordfreq) = letters[1:5]
rep(names(wordfreq), times = wordfreq)
#1
Try this:
rep(names(wordfreq), times = wordfreq)
Here is a reproducible example:
这是一个可重复的例子:
wordfreq = sample.int(10, 5, replace = TRUE)
names(wordfreq) = letters[1:5]
rep(names(wordfreq), times = wordfreq)