使用 map2_ 迭代 f(x, y) 的问题
issues with Iterating over f(x, y) using map2_
我正在使用 LastFM API 的包装器来搜索曲目标签。
包装函数是...
devtools::install_github("juyeongkim/lastfmr")
track_getInfo("track", "artist", api_key= lastkey)
我将自己的函数定义为
INFOLM <- function(x= track, y= artist) {
output <- track_getInfo(x,y,api_key = lastkey)
output <- flatten(output)
output_1 <- output[["tag"]][["name"]]
return(output_1)
}
然后从我更大的数据框中准备我的列表元素
artist4lf <- c(small_descriptive[1:10,2])
track4lf <- c(small_descriptive[1:10,3])
x<- vector("list", length = length(track4lf))
y<- vector("list", length = length(artist4lf))
names(x) <- track4lf
names(y) <- artist4lf
那么……
map2_df(track4lf, artist4lf, INFOLM)
我每次都收到 0x0 小标题...有人有什么建议吗?
我认为如果您只是从 track_getInfo
函数中删除 api_key
参数,您的 INFOLM
函数将起作用。
此外,不确定您是否需要在此处使用 purrr::map2
,您应该能够使用带有 rowwise
和 mutate
的 small_descriptive
数据框来添加列( s) 你想要的。
开始吧,使用 testdf
就好像它是您的 small_descriptive
数据框,只有 track
和 artist
列。
library(lastfmr)
library(dplyr)
library(tidyr)
testdf <- tribble(
~Artist, ~Track,
"SmashMouth", "All Star",
"Garth Brooks", "The Dance"
)
INFOLM <- function(x= track, y= artist) {
output <- track_getInfo(x,y)
output <- flatten(output)
output_1 <- output[["tag"]][["name"]]
return(paste(output_1, collapse = ","))
}
testdf %>% rowwise %>%
mutate(stuff = INFOLM(Track, Artist)) %>%
tidyr::separate(stuff, c("Tag1", "Tag2", "Tag3", "Tag4", "Tag5"), sep = ",")
我正在使用 LastFM API 的包装器来搜索曲目标签。 包装函数是...
devtools::install_github("juyeongkim/lastfmr")
track_getInfo("track", "artist", api_key= lastkey)
我将自己的函数定义为
INFOLM <- function(x= track, y= artist) {
output <- track_getInfo(x,y,api_key = lastkey)
output <- flatten(output)
output_1 <- output[["tag"]][["name"]]
return(output_1)
}
然后从我更大的数据框中准备我的列表元素
artist4lf <- c(small_descriptive[1:10,2])
track4lf <- c(small_descriptive[1:10,3])
x<- vector("list", length = length(track4lf))
y<- vector("list", length = length(artist4lf))
names(x) <- track4lf
names(y) <- artist4lf
那么……
map2_df(track4lf, artist4lf, INFOLM)
我每次都收到 0x0 小标题...有人有什么建议吗?
我认为如果您只是从 track_getInfo
函数中删除 api_key
参数,您的 INFOLM
函数将起作用。
此外,不确定您是否需要在此处使用 purrr::map2
,您应该能够使用带有 rowwise
和 mutate
的 small_descriptive
数据框来添加列( s) 你想要的。
开始吧,使用 testdf
就好像它是您的 small_descriptive
数据框,只有 track
和 artist
列。
library(lastfmr)
library(dplyr)
library(tidyr)
testdf <- tribble(
~Artist, ~Track,
"SmashMouth", "All Star",
"Garth Brooks", "The Dance"
)
INFOLM <- function(x= track, y= artist) {
output <- track_getInfo(x,y)
output <- flatten(output)
output_1 <- output[["tag"]][["name"]]
return(paste(output_1, collapse = ","))
}
testdf %>% rowwise %>%
mutate(stuff = INFOLM(Track, Artist)) %>%
tidyr::separate(stuff, c("Tag1", "Tag2", "Tag3", "Tag4", "Tag5"), sep = ",")