Creating array with lists as elements
1
0
Entering edit mode
Haiying.Kong ▴ 110
@haiyingkong-9254
Last seen 5.0 years ago
Germany

I am trying to create an array object.

> a = array(NA, c(4,1,1))
> class(a)
[1] "array"
> a[1,1,1] = "test"
> class(a)
[1] "array"
> a[2,1,1] = list(1:5)
> class(a)
[1] "list"

I want the object a to stay as an array after getting a list as the value for a[2,1,1].

How can I do this?

R • 633 views
ADD COMMENT
0
Entering edit mode
@martin-morgan-1513
Last seen 6 weeks ago
United States

Not a Bioconductor question, so probably better to ask on StackOverflow or similar. But create the array using list() rather than logical (NA).

> a = array(list(), c(4, 1, 1))
> a[2, 1, 1] = list(1:5)
> class(a)
[1] "array"
> typeof(a)
[1] "list"
> a
, , 1

     [,1]     
[1,] NULL     
[2,] Integer,5
[3,] NULL     
[4,] NULL     

> a[2, 1, 1]
[[1]]
[1] 1 2 3 4 5
ADD COMMENT
0
Entering edit mode

Thank you very much.

ADD REPLY

Login before adding your answer.

Traffic: 794 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6