Re: [R] "[[" gotcha

From: Barry Rowlingson <>
Date: Tue 16 Jan 2007 - 10:44:26 GMT

Robin Hankin wrote:

> The error is given because after B[[1]] <- a, the variable B is
> just a scalar and
> not a matrix (why is this?)

  Because [[i]] indexes more general vectors, and if you do B[[1]] when B is NULL, R doesnt know if you want B to be a list or a simple vector.

  If you initialise B as an empty list then R knows:

  > B=list()
  > B
  > B[[1]]=b
  > B

  [1,] 1

Barry mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Tue Jan 16 21:59:18 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 16 Jan 2007 - 11:30:28 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.