我有一个数据框,其中有一Genre
列的行如Action,Romance
. 我想拆分这些值并创建一个二进制向量。如果Action,Romance,Drama
是所有可能的流派,那么上述行将1,1,0
在输出数据框中。
我发现了这个和这个SO 帖子,以及这个 CRAN 文档涵盖 cSplit_e,但是当我使用它时,我没有得到二进制数据帧输出,我得到的是带有一些加扰值的原始数据帧。
a = cSplit_e(df4, "Genre", sep = ",", mode = "binary", type = "character", drop=TRUE, fixed=TRUE,fill = 0)
编辑:问题似乎是它将新列添加到旧数据框中,而不是创建新框架。我怎样才能让流派进入他们自己的框架?
> names(a)
[1] "Title" "Year" "Rated" "Released" "Runtime" "Genre" "Director" "Writer" "Actors"
[10] "Plot" "Language" "Country" "Awards" "Poster" "Metascore" "imdbRating" "imdbVotes" "imdbID"
[19] "Type" "tomatoMeter" "tomatoImage" "tomatoRating" "tomatoReviews" "tomatoFresh" "tomatoRotten" "tomatoConsensus" "tomatoUserMeter"
[28] "tomatoUserRating" "tomatoUserReviews" "tomatoURL" "DVD" "BoxOffice" "Production" "Website" "Response" "Budget"
[37] "Domestic_Gross" "Gross" "Date" "Genre_Action" "Genre_Adult" "Genre_Adventure" "Genre_Animation" "Genre_Biography" "Genre_Comedy"
[46] "Genre_Crime" "Genre_Documentary" "Genre_Drama" "Genre_Family" "Genre_Fantasy" "Genre_Film-Noir" "Genre_Game-Show" "Genre_History" "Genre_Horror"
[55] "Genre_Music" "Genre_Musical" "Genre_Mystery" "Genre_N/A" "Genre_News" "Genre_Reality-TV" "Genre_Romance" "Genre_Sci-Fi" "Genre_Short"
[64] "Genre_Sport" "Genre_Talk-Show" "Genre_Thriller" "Genre_War" "Genre_Western"