Skip to content

Instantly share code, notes, and snippets.

@saraswatmks
Created May 30, 2017 07:33
Show Gist options
  • Save saraswatmks/d6793248f22ca75e1563acde8483e2cc to your computer and use it in GitHub Desktop.
Save saraswatmks/d6793248f22ca75e1563acde8483e2cc to your computer and use it in GitHub Desktop.
Read files in R
library(data.table)
library(jsonlite)
#### Train
train <- fromJSON("train_data.json")
train_data <- data.table(ID = unlist(names(train)))
train_data[, `:=` (genres = unlist(lapply(train, '[',1)),
titles = unlist(lapply(train, '[',2)),
cities = unlist(lapply(train, '[', 3)),
segment = unlist(lapply(train, '[',4)),
dow = unlist(lapply(train, '[',5)),
tod = unlist(lapply(train, '[', 6))
)]
#### Test
test <- fromJSON("test_data.json")
test_data <- data.table(ID = unlist(names(test)))
test_data[,`:=` (genres = unlist(lapply(test, '[',1)),
titles = unlist(lapply(test, '[',2)),
tod = unlist(lapply(test, '[', 3)),
cities = unlist(lapply(test, '[',4)),
dow = unlist(lapply(test, '[',5))
)]
str(train)
str(test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment