[R] Lists heading in an array of lists in R

Dénes Tóth toth.denes at ttk.mta.hu
Fri Jan 22 09:45:51 CET 2016


Hi,

Provide a list of a list in the second assignment:

--
TunePar <- matrix(list(NULL), 2, 2)
TunePar[2,1] <- list(list(G = 2))
TunePar[2,1]
TunePar[2,1][[1]]$G
TunePar[[2]]$G
---

The point is that "[" returns the list element of the same level as the 
original object (TunePar in the present example). So in the assignment 
if you extracted one element on the LHS, it expects a one-element vector 
on the RHS, e.g., check this out:
---
# this throws an error
TunePar[1,2] <- list(H = 1:3, I = letters[1:2])

# this is fine
TunePar[1,2] <- list(list(H = 1:3, I = letters[1:2]))
TunePar[1,2]
TunePar[1,2][[1]]$I
---

HTH,
  Denes



On 01/22/2016 08:29 AM, TJUN KIAT TEO wrote:
> TunePar<-matrix(list(Null),2,2)
>
> TunePar[1,1]=list(G=2)



More information about the R-help mailing list