如果我有一个简单的df,如下所示:
mtcars
mpg cyl disp hp drat wt ...
Mazda RX4 21.0 6 160 110 3.90 2.62 ...
Mazda RX4 Wag 21.0 6 160 110 3.90 2.88 ...
Datsun 710 22.8 4 108 93 3.85 2.32 ...
............
Run Code Online (Sandbox Code Playgroud)
假设第一列(row.names)是一长串汽车,那么我将如何仅使用该列来创建频率词云。我尝试过wordcloud(mtcars$row.names)但出现以下错误:
UseMethod(“ TermDocumentMatrix”,x)中的错误:没有适用于'TermDocumentMatrix'的适用方法应用于类“ NULL”的对象
也许wordcloud是错误的软件包?
您尝试mtcars$row.names在控制台上打字吗?
将行名称作为向量的方法是使用rownames(mtcars)。像这样:
library(wordcloud) # this requires the tm and NLP packages
wordcloud(rownames(mtcars), min.freq=1) # w/o min.req=1, you get just "merc"
Run Code Online (Sandbox Code Playgroud)
