-1

I need to create potentially a huge number of variables. I would like to name them

var.1, var.2, var.3 etc.

I am thinking about using a for loop. To experiment, I use only a single iteration, i.e. i=1. I've tried paste() and print(), but neither works.

paste("detect.","1", sep="") = 2
Error in paste("detect.", "1", sep = "") = 2 : 
target of assignment expands to non-language object

print("detect.","1", sep="") = 1
Error in print("detect.", "1", sep = "") = 1 : 
target of assignment expands to non-language object

I've also tried to add as.vector() and others, but none of them works.

If possible, can anyone provide a better solution without using for loops?

Thanks

4

1 回答 1

2

你想要assign

> assign(paste("detect.", "1", sep=""), 2)
> detect.1
[1] 2
于 2014-02-07T23:03:46.563 回答