-1

I am trying to loop over the following list of data frames in R:

ll <- list(week_32, week_33, week_34, week_35, week_36, week_37, week_38, week_39, week_40, week_41, week_42, week_43, week_44, week_45, week_46, week_47, week_48, week_49)

First I want to remove duplicates in two columns:

lapply( ll, function(x){x= x[!duplicated(x[,c("PZS_Id", "VL_Id")]),]})

This works all fine. In the consequent step I want to dcast each of the elements in the list and save the result in a new file. My trial was the following but I get the following error: Error: value.var (VL_Status) not found in input

`for (x in 32:max(data$week)){nam <- paste("week", "cast", x, sep="_")assign(nam, dcast(noquote(paste("week",x,sep="_")),PZS_Id + ï..Datum + Umfang.Id + PZS_Status + Date + week ~ VL_Id, value.var= 'VL_Status' ))}`

I assume this is due to the fact that noquote(paste("week",x,sep="_")) cannot be recognized as a data frame. Does anyone have an idea how to solve this.

Raphael
  • 116
  • 7

1 Answers1

0

Try eval(parse(text =nam))

Minimal example:

library(reshape2)
week_32 <- data.frame(id = 1, column1 = sample(LETTERS,10), column2 = runif(10))
x<-32
nam <-noquote(paste("week",x,sep="_"))
new <- dcast(eval(parse(text =nam)),  id  ~ column1)

Relevant - Convert string to a variable name

Jason
  • 581
  • 3
  • 8