credit: Nathan Stephens, Rstudio
# Group the pollution data.frame by city for comparison
pollution <- group_by(pollution, city) %>%
summarise(
mean = mean(amount, na.rm = TRUE),
sum = sum(amount, na.rm = TRUE),
n = n()
)
# install.packages('ggmap')
library(ggmap)
qmap('Seattle')
https://api.spotify.com/v1/search?q=adele&type=artist
{
artists: {
href: "https://api.spotify.com/v1/searc...",
items: [{
external_urls: {
spotify: "https://open.spotify...."
},
followers: {
href: null,
total: 4093432
},
}
}
# Base URL of API
base <- 'https://api.spotify.com/v1/search?'
# Parameters
search <- 'q=adele'
type <- '&type=artist'
# Query string
query_url <- paste0(base, search, type)
# Read in data
library(jsonlite)
data <- fromJSON(query_url)
# Let's do something silly
people <- data.frame(names = c('Spencer', 'Jessica', 'Keagan'))
favorites <- data.frame(
food = c('Pizza', 'Pasta', 'salad'),
music = c('Bluegrass', 'Indie', 'Electronic')
)
people$favorites <- favorites
# Columns of our people data.frame
names(people)
[1] "names" "favorites"
# Flatten it!
flattened <- flatten(people)
names(flattened)
[1] "names" "favorites.food" "favorites.music"