我有一个数据集电影。
head(Movies)
如何获取 MovieID 为“0000008”的行?我努力了:
t1 = subset(Movies, "MovieID" == "0000008")
t2 <- Movies[ which(Movies["MovieID"]=="0000008"), ]
head(t1)
head(t2)
两者都返回空数据集,这是错误的,因为我可以看到 ID 为“0000008”的行。
编辑:我尝试从 MovieID 中删除“”,但这会引发错误:
子集.matrix(电影,MovieID ==“0000008”)中的错误:找不到对象'MovieID'
编辑:电影数据是这样获得的:
URL = "https://raw.githubusercontent.com/sidooms/MovieTweetings/master/latest/movies.dat"
MovieText = readLines( remote.file(URL) ) # HACK!!!
Movies = matrix( sapply( MovieText,
function(x) unlist(strsplit(sub(" [(]([0-9]+)[)]", "::\\1",x),"::"))[1:4] ),
nrow=length(MovieText), ncol=4, byrow=TRUE )
colnames(Movies) = c("MovieID", "MovieTitle", "Year", "Genres")