I have a tall data.frame of data from multiple experiments in the format (toy example)
experiment parameter value
exp1 temp 25
exp1 press 1
exp2 temp 30
exp2 press 1
I want to feed an individual experiment to a function my.fun(filter(df, experiment == exp1)) and within that function, I want to break out the variables to temp = 25 and press = 1. I can use df2 = spread(df, parameter, value) but then I have df2$temp and df2$press. How can I just assign them as variables with the name of the parameter? I can do:
for(j in 1:length(names(df2))){
assign(names(df2)[j],df2[j])
}
but is there a way to do it without the loop? I've tried things like sapply(names(df2),assign,df2) but I don't understand the error message given. It sounds like assign is kind of a maligned function. Is there a better way to do this generally?