提取独特的流派及其计数并使用索引键存储在数据框中
Extract the unique genres and its count and store in data frame with index key
如何在 R 编程中拆分一个变量的多个值。
例如,在图像中,类型在其单元格中有多个值。如何将它们分开并计算 table.
中的值
我们可以使用separate_rows
library(dplyr)
library(tidyr)
df1 %>%
separate_rows(Genre) %>%
count(Genre)
或使用base R
table(unlist(strsplit(df$Genre, ",\s*")))
table(trimws(unlist(strsplit(df$Genre, split = ","))))
如何在 R 编程中拆分一个变量的多个值。
我们可以使用separate_rows
library(dplyr)
library(tidyr)
df1 %>%
separate_rows(Genre) %>%
count(Genre)
或使用base R
table(unlist(strsplit(df$Genre, ",\s*")))
table(trimws(unlist(strsplit(df$Genre, split = ","))))