0

do you think I can add a melt function in this loop?

for (i in unique(df$year))

    {dfnames<- paste("df",i, sep = "_")
    assign(dfnames, df[df$year==i,])}

I just want to reshape all the subsets that I am generating with that loop. I would like to add this command in the loop, if it is possible:

melt(df_i, id.vars = c("Company_name","year","ID","Status"),na.rm=F)
  • Thank you. I will do it, sorry. –  Feb 22 '18 at 15:27
  • Most things are possible. The question here is what you're trying to achieve. There's an eerie feeling that there's a better way of approaching this using lists. – Roman Luštrik Feb 22 '18 at 15:44
  • Yes, maybe it would be better. I need to split the whole dataset in subsets according to the variable year, then I want to reshape them one by one, and then I need to put them together again. –  Feb 22 '18 at 16:43
  • Please provide a small example. You could split the data using `split`, `sapply` or `lapply` a function through the list. This has been addressed on SO many times, feel free to have fun with the search function. – Roman Luštrik Feb 23 '18 at 09:59
  • You are right. Sorry, thank you. –  Feb 24 '18 at 07:56

0 Answers0