我有一個tibble。我們如何一列分爲基於多個的「|」?
library(tidyverse)
df <- tibble(
id = 1:4,
genres = c("Action|Adventure|Science Fiction|Thriller",
"Adventure|Science Fiction|Thriller",
"Action|Crime|Thriller",
"Family|Animation|Adventure|Comedy|Action")
)
df
我想通過流派分開 「|」和填充NA的空列。
這是我做過什麼:
df %>%
separate(genres, into = c("genre1", "genre2", "genre3", "genre4", "genre5"), sep = "|")
然而,每個字母后它被分離。
使用'cSplit'從'splitstackshape'包,'CSPLIT(DF, 「流派」, 「|」)'。 –
請包含拆分的代碼。 – neilfws