---------- Forwarded message ---------- From: Carlos Petti <carlos.pe...@gmail.com> Date: 2010/8/10 Subject: Re: [R] List of lists ? To: David Winsemius <dwinsem...@comcast.net>
Perhaps a solution : x <- list() x[[2]] <- list() x[[2]][[1]] <- c(1, 2, 3) x[[2]][[2]] <- c(3, 2, 1) 2010/8/10 Carlos Petti <carlos.pe...@gmail.com>: > Thanks for answer. > > I read the error messages but I did not find the solution :-( > > Your solution works. > But, a new problem remains because I want > to use the list of lists as follows : > > x <- list(list()) > > x[[2]][[1]] <- c(1, 2, 3) > x[[2]][[2]] <- c(3, 2, 1) > > Thanks in advance, > Carlos > > 2010/8/9 David Winsemius <dwinsem...@comcast.net>: >> >> On Aug 9, 2010, at 12:57 PM, Carlos Petti wrote: >> >>> Dear list, >>> >>> I have to use a list of lists containing vectors. >>> >>> For instance : >>> >>> [[1]] >>> [[1]][[1]] >>> [1] 1 2 3 >>> >>> [[1]][[2]] >>> [1] 3 2 1 >>> >>> I want to attribute vectors to the main list >>> >>> without use of an intermediate list, >>> >>> but it does not work : >> >> More specifically it produces an error that has information in it. >>> x[[1]][[1]] <- c(1, 2, 3) >> Error in `*tmp*`[[1]] : subscript out of bounds >> >>> >>> x <- list() >>> x[[1]][[1]] <- c(1, 2, 3) >>> x[[1]][[2]] <- c(3, 2, 1) >> >> So thinking perhaps we just needed another level of subscripting "available" >> I tried: >> >>> x <- list(list()) >>> x[[1]][[1]] <- c(1, 2, 3) >>> x[[1]][[2]] <- c(3, 2, 1) >>> x >> [[1]] >> [[1]][[1]] >> [1] 1 2 3 >> >> [[1]][[2]] >> [1] 3 2 1 >> >> Success. Moral: Read the error messages for meaning or at least clues. >> (Further testing showed that almost anything inside the original list() >> call, even NULL, would have created enough structure for the interpreter to >> work with. >> >>> >> >> David Winsemius, MD >> West Hartford, CT >> >> > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.