for assign and mutate

Hello every one,

I tried to run this code (with no success):

chanel_code=c( "BA","CS","DM","DS","EN","IA","MG","PS","TM")

for (i in chanel_code) {
  assign(paste("prospect_",i,sep="", collapse = NULL,recycle0 = FALSE),(aggregate(na_adss_score ~ month_year + na_appl_status, paste("new_account_",i, sep="",collapse = NULL, recycle0 = FALSE),mean) %>% 
                                                                          mutate(aggregate(na_pcn_no ~ month_year + na_appl_status,  paste("new_account_",i, sep="",collapse = NULL, recycle0 = FALSE), length))))
  • :sleepy:*

Error in eval(predvars, data, env) :
argument 'envir' incorrect de type 'character'

would you mind please helping me.

thanks in advance

I don't know the purpose intent of your code.
but the error is directly from your not respecting the parameters that assign can take. You could perhaps draw your own attention to what the parameters are and how they should be used by explicitly using their names, rather than passing by position.

assign(x, value, pos = -1, envir = as.environment(pos),
       inherits = FALSE, immediate = TRUE)

i.e. if you want some name x and some value, make it clear what they are.


sidenote, it seems suspect to be mixing base aggregate with dplyr's mutate. if you are a dplyr user why not group by and summarise ?
final comment, recycle0 default is false, so you can skip specifying it and make your code shorter in that way.

I thank you for your comments

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.