【发布时间】:2018-01-06 08:31:46
【问题描述】:
我有一个数据框,其中包含一列歌曲标题、标签信息和其他杂乱的字符串数据。我还有一个特定歌曲标题的孤立向量。我想从歌曲标题中过滤掉所有不匹配歌曲的角色。我正在使用类似的东西,但显示错误。
song.list <- c("Song.1","Song.2", "Song.3")
Mydata$Songs <- My data column containing all sorts of things including the songs I'm after
levels(Mydata$Songs)[(Mydata$Songs) %in% song.list] <- "" #I'd like the opposite of this
levels(Mydata$Songs)![(Mydata$Songs) %in% song.list] <- ""#My use of '!' doesn't work
我知道在没有 ! 的情况下使用上述索引可以用空格替换我的歌曲列表,但我正在尝试用空格替换其他所有内容。我的列表中有大约 29 首歌曲,单列中有大约 1000 行杂乱的字符串数据。我也试过 gsub 和 grep 无济于事。
【问题讨论】:
-
您将
!放在错误的位置![!(Mydata$Songs) %in% song.list].