[R] List elements of NULL to value
ROLL Josh F
JRoll at lcog.org
Tue Nov 30 00:13:03 CET 2010
Yes that works thank you, and as always I feel foolish for asking. You guys are great.
Lane Council of Governments
jroll at lcog.org
From: Phil Spector [mailto:spector at stat.berkeley.edu]
Sent: Monday, November 29, 2010 12:58 PM
To: ROLL Josh F
Cc: r-help at r-project.org
Subject: Re: [R] List elements of NULL to value
A = lapply(A,function(x)if is.null(x) 0 else x) or
for(i in 1:length(A))if(is.null(A[[i]]))A[i] = 0
do what you want?
- Phil Spector
Statistical Computing Facility
Department of Statistics
spector at stat.berkeley.edu
On Mon, 29 Nov 2010, LCOG1 wrote:
> Hi everyone,
> I am posting this because i know its easy and i cant for the life
> of me figure out how to do it though i have tried and through a
> ridiculously complex loop made it happen. I need to convert some list
> elements of NULL value to 0s so they mesh with my data frame properly.
> So for
>  1
> Would instead return
>  1
>  0
> The nabble posts seem to indicate dealing with NULLs can be tricky so
> i am attributing my lack of success to that, mainly so i can live with
> myself and asking the list such a simple question. Sorry again guys.
> View this message in context:
> p3064384.html Sent from the R help mailing list archive at Nabble.com.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help