jupyter irkernel - Filter records from table in R -


i have dataset movies.

head(movies) 

output of head(movies)

how fetch rows movieid "0000008"? have tried:

t1 = subset(movies, "movieid" == "0000008") t2 <- movies[ which(movies["movieid"]=="0000008"), ] head(t1) head(t2) 

both return empty datasets, wrong can see row id "0000008".

edit: have tried removing "" movieid, throws error:

error in subset.matrix(movies, movieid == "0000008"): object 'movieid' not found

edit: movie data obtained as:

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") 

your nrow should length(movietext)/4

url = "https://raw.githubusercontent.com/sidooms/movietweetings/master/latest/movies.dat" movietext = readlines( url ) # hack!!! movies = matrix( sapply( movietext,     function(x) unlist(strsplit(sub(" [(]([0-9]+)[)]", "::\\1",x),"::"))[1:4] ),     nrow=length(movietext)/4, ncol=4, byrow=true ) colnames(movies) = c("movieid", "movietitle", "year", "genres")  #if want work matrix, use subset(movies, movies[,"movieid"]=="0000008") 

edit: data.frame , data.table subsetting

library(data.table)  moviesdf <- data.frame(movies) moviesdt <- data.table(movies)  moviesdf[moviesdf["movieid"] == "0000008", ] moviesdt[movieid == "0000008", ] 

btw: love hack!!! comment.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -