这个
drop
参数仅适用于要拆分的列,而不适用于
data.frame
. 因此,要随后仅提取拆分的列,请使用原始列名并仅提取这些列。
例子:
> a <- cSplit_e(df4, "Genre", ",", mode = "binary", type = "character", fill = 0, drop = TRUE)
> a
id Genre_Action Genre_Drama Genre_Romance
1 1 1 0 1
2 2 1 1 1
> a[startsWith(names(a), "Genre")]
Genre_Action Genre_Drama Genre_Romance
1 1 0 1
2 1 1 1
哪里:
df4 <- structure(list(Genre = c("Action,Romance", "Action,Romance,Drama"), id = 1:2),
.Names = c("Genre", "id"), row.names = 1:2, class = "data.frame")