[R] lapply problem
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Fri Aug 13 13:48:03 CEST 2004
"Luis Rideau Cruz" <Luisr at frs.fo> writes:
> R-help,
>
> I wish to replace NULL elements(or missing) in the following list :
...
> If I use
> lapply(z2,function(x) ifelse(is.null(x),0,as.numeric(x)))
...
> i.e,only the first element in z2
ifelse(....) gives a result that is the same length as the condition,
and is.null(x) has length 1. You want
if (is.null(x)) 0 else as.numeric(x)
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list