Maiasaura Maiasaura - 1 year ago 77
R Question

How to name variables on the fly in R?

Is it possible to create new variable names on the fly?

I'd like to read data frames from a list into new variables with numbers at the end. Something like orca1, orca2, orca3...

If I try something like


I get this error

target of assignment expands to non-language object

Is there another way around this?

Answer Source

Use assign:

assign(paste("orca",i,sep=""), list_name[[i]])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download