How to name variables on the fly?

前端 未结 6 1652
执念已碎
执念已碎 2020-11-22 10:11

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, o

6条回答
  •  孤城傲影
    2020-11-22 10:28

    Don't make data frames. Keep the list, name its elements but do not attach it.

    The biggest reason for this is that if you make variables on the go, almost always you will later on have to iterate through each one of them to perform something useful. There you will again be forced to iterate through each one of the names that you have created on the fly.

    It is far easier to name the elements of the list and iterate through the names.

    As far as attach is concerned, its really bad programming practice in R and can lead to a lot of trouble if you are not careful.

提交回复
热议问题