Consider the following example:
Vars <- c("car","bike","lorry")
Dat <- c(10,20,22)
for (i in 1:length(Vars)){
assign(Vars[i],Dat[i])
}
Here, I would like to generate three variables in the workspace named according to the entries in Vars
and the values in Dat
. At the moment I am using a loop, but I have been trying to remove the loop by using apply, how would be the best way of doing this?