[R] Why a list of NULL's are reduced to NULL?

Peng Yu pengyu.ut at gmail.com
Fri Dec 11 17:43:50 CET 2009


The following examples are confusing to me. It is OK, to assigned NULL
to one element in a list. The result is still a list. However, a list
of NULL's are reduced to NULL. I don't understand how this conversion
occurs. Could somebody let me know what is going on?

> X=matrix(1:8, nr=4)
> apply(X,1, function(x) {if(x[[1]]==3){NULL}else{x[[1]]}})
[[1]]
[1] 1

[[2]]
[1] 2

[[3]]
NULL

[[4]]
[1] 4

> apply(X,1, function(x) {NULL})
NULL




More information about the R-help mailing list