-4

If I have a data set "c" and one variable "x" inside.

The x variable only has two observation is 5 and 6.

I want to assign two variable c1, c2 for c$x[1] and c$x[2]

I tried to use the function below, but it does not work.

rf<-function(){
    for(i in 1:2)
assign(paste("c", i,sep=""),paste("c$x[",i, "]" ,sep="")])}

How could I revise the syntax to get the results?

zx8754
  • 46,390
  • 10
  • 104
  • 180
Elong Chen
  • 99
  • 1
  • 7

1 Answers1

0

Dont use paste in the second argument for assign.

assign(paste("c", i,sep=""),c$x[i])) will work.

raiyan
  • 769
  • 5
  • 15