Вы можете просто восстановить столбцы, используя оператор доступа $
. Основываясь на комментарии Мориса Эверса о размере выборки ~ 3 Гб, я создал пример на основе доступной выборки данных Набор данных Yelp JSON, business.json (см. В конце публикации). Кроме того, вам нужно будет объединить Categories
с использованием paste0
в вектор символов, чтобы избежать многострочной записи для каждой сущности JSON.
yelp.R
library(jsonlite)
df <- jsonlite::fromJSON("business.json")
df$RestaurantsTakeOut <- df$attributes$RestaurantsTakeOut
df_bp <- df$attributes$BusinessParking
df_wh <- df$hours
df <- cbind(df, df_bp, df_wh)
df$categories <- sapply(df$categories, paste0, collapse = ", ")
df$attributes <- NULL
df$hours <- NULL
str(df)
Выход:
'data.frame': 2 obs. of 26 variables:
$ business_id : chr "tnhfDv5Il8EaGSXZGiuQGg" "tnhfDv5Il8EaGSXZGiuQGg"
$ name : chr "Garaje" "Garaje"
$ neighborhood : chr "SoMa" "SoMa"
$ address : chr "475 3rd St" "475 3rd St"
$ city : chr "San Francisco" "San Francisco"
$ state : chr "CA" "CA"
$ postal code : chr "94107" "94107"
$ latitude : num 37.8 37.8
$ longitude : num -122 -122
$ stars : num 4.5 4.5
$ review_count : int 1198 1198
$ is_open : int 1 1
$ categories : chr "Mexican, Burgers, Gastropubs" "Mexican, Burgers, Gastropubs"
$ RestaurantsTakeOut: logi TRUE TRUE
$ garage : logi FALSE FALSE
$ street : logi TRUE TRUE
$ validated : logi FALSE FALSE
$ lot : logi FALSE FALSE
$ valet : logi FALSE FALSE
$ Monday : chr "10:00-21:00" "10:00-21:00"
$ Tuesday : chr "10:00-21:00" "10:00-21:00"
$ Friday : chr "10:00-21:00" "10:00-21:00"
$ Wednesday : chr "10:00-21:00" "10:00-21:00"
$ Thursday : chr "10:00-21:00" "10:00-21:00"
$ Sunday : chr "11:00-18:00" "11:00-18:00"
$ Saturday : chr "10:00-21:00" "10:00-21:00"
business.json
[{
"business_id": "tnhfDv5Il8EaGSXZGiuQGg",
"name": "Garaje",
"neighborhood": "SoMa",
"address": "475 3rd St",
"city": "San Francisco",
"state": "CA",
"postal code": "94107",
"latitude": 37.7817529521,
"longitude": -122.39612197,
"stars": 4.5,
"review_count": 1198,
"is_open": 1,
"attributes": {
"RestaurantsTakeOut": true,
"BusinessParking": {
"garage": false,
"street": true,
"validated": false,
"lot": false,
"valet": false
}
},
"categories": [
"Mexican",
"Burgers",
"Gastropubs"
],
"hours": {
"Monday": "10:00-21:00",
"Tuesday": "10:00-21:00",
"Friday": "10:00-21:00",
"Wednesday": "10:00-21:00",
"Thursday": "10:00-21:00",
"Sunday": "11:00-18:00",
"Saturday": "10:00-21:00"
}
},
{
"business_id": "tnhfDv5Il8EaGSXZGiuQGg",
"name": "Garaje",
"neighborhood": "SoMa",
"address": "475 3rd St",
"city": "San Francisco",
"state": "CA",
"postal code": "94107",
"latitude": 37.7817529521,
"longitude": -122.39612197,
"stars": 4.5,
"review_count": 1198,
"is_open": 1,
"attributes": {
"RestaurantsTakeOut": true,
"BusinessParking": {
"garage": false,
"street": true,
"validated": false,
"lot": false,
"valet": false
}
},
"categories": [
"Mexican",
"Burgers",
"Gastropubs"
],
"hours": {
"Monday": "10:00-21:00",
"Tuesday": "10:00-21:00",
"Friday": "10:00-21:00",
"Wednesday": "10:00-21:00",
"Thursday": "10:00-21:00",
"Sunday": "11:00-18:00",
"Saturday": "10:00-21:00"
}
}]