strange behaviour with loops and lists
On Sun, May 19, 2013 at 7:02 PM, peter dalgaard <pdalgd at gmail.com> wrote:
(The first example really had 2:3, not 5:7, right?)
Indeed. I simplified the example mid-email.
The essential bit is that to assign to the 2nd element of a list, it needs to have at least two elements:
Thanks for the explanations. Regards, Liviu
x <- list() x[[2]] <- 123 x
[[1]] NULL [[2]] [1] 123 assigning to an element with a specific name just requires there is an element of that name:
x[["2"]] <- 321 x
[[1]] NULL [[2]] [1] 123 $`2` [1] 321 In both cases, x will be extended if needed, so that the required element exists. Notice that there is no relation between the name and the number of a list element; e.g., x[["2"]] is the 3rd element in the above example. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail