manoj manoj - 25 days ago 21
R Question

R - create list by numeric sequence

I need to create a List as below:

A = list(1,2,3,4)


The number of list elements is stored in a variable X (X=4 in this example). I tried using the below script but getting a different output

A = list(seq (1,X,1))


I get output as

[[1]]
[1] 1 2 3 4


.............................................................

I NEED output as below

[[1]]
[1] 1

[[2]]
[1] 2

[[3]]
[1] 3

[[4]]
[1] 4


Thanks for your help

Answer

Please have a look at this:

x<-4
as.list(seq (1,x,1)) 
Comments