你可以做这样的:
# First, vectorize function
rottenrate <- function(movie){
require(RJSONIO)
link <- paste("http://www.omdbapi.com/?t=", movie, "&y=&plot=short&r=json&tomatoes=true", sep = "")
jsonData <- fromJSON(link)
return(jsonData)
}
vrottenrate <- Vectorize(rottenrate, "movie", SIMPLIFY = FALSE)
# Now, query and combine
movies <- c("inception", "toy story")
df <- do.call(rbind, lapply(vrottenrate(movies), function(x) as.data.frame(t(x), stringsAsFactors = FALSE)))
dplyr::glimpse(df)
# Observations: 2
# Variables:
# $ Title (chr) "Inception", "Toy Story"
# $ Year (chr) "2010", "1995"
# $ Rated (chr) "PG-13", "G"
# $ Released (chr) "16 Jul 2010", "22 Nov 1995"
# $ Runtime (chr) "148 min", "81 min"
# $ Genre (chr) "Action, Mystery, Sci-Fi", "Animation,
# ...
有趣数据库顺便说一句... :-)
那么你所期望的列做您的数据帧?您能否提供样本电影ID并显示该输入的所需输出? – MrFlick