简体   繁体   中英

Placeholder for character vector in purrr:map?

I am trying to iterate over a character vector "outcomes"

results <- map(outcomes, run("Female", ., predictors))

"run" is a user-defined function and "Female" and predictors are additional arguments I pass to the function. Period does not seem to work as a placeholder for each element of outcomes :

 Error in .f(.x[[i]], ...) : object '.' not found 

I would really like to use map instead of a loop.

it does not identify . as a valid parameter for your run function. Here, is a sample code which works well:

run<-function(outcome,gender,key,predictor){
  paste0(outcome," ",gender," ",key," ",predictor)

}

and then call it by map:

outcome=c(8:11)

library(purrr)
map(outcome,run,gender="Female",key=1,predictor=5  )

if your run function has multiple argument, all of the parameters of run, are the parameters of map now. But, in your code, you did not follow it.

For complete explanation, please find this link .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM