0

I have a list converted from a JSON-string which looks like this:

print(p)
$species
[1] "Ratte"
$value
[1] "fitness"
$aggregation
[1] "mean"

I would like to use the information given the list as arguments in a function to transform a data-frame [Data] like this:

transformedData <- dcast(
Data[Data$species==p[[1]],],run_nr~paste(p[[2]],"_value",sep = ""),fun.aggregate = p[[3]]
)

This part

Data[Data$species==p[[1]],]

does work, of course. unfortunately I do not know how to deal with the character strings of the other ones. I tried to convert the variables with as.name(paste(p[[2]],"_value",sep = "")) and as.function(p[[3]]), without success... does anyone knows a workaround?

Flox
  • 1
  • 1

1 Answers1

0

Got it! For the string addressing the column in the data.frame use eval and parse, like in this post:

How to convert a string in a function into an object?

for the function use str2lang("mean")

works like a charm!!!

Flox
  • 1
  • 1