How to remove NaN in large list

2019-08-26 06:50发布

问题:

I'm trying to remove my NaNs in a very large list. Removing NAs is quite easy with

My.List[!is.na(My.List)]

But using

My.List[!is.nan(My.List)]

is not an implemented method for lists (R-Error).

Can you help me? Thanks!

回答1:

Try

 MyList <- na.omit(My.List)


回答2:

You can use sapply to find the NaNs

> x <- list(1, NaN, 3)
> 
> x[!sapply(x, is.nan)]
[[1]]
[1] 1

[[2]]
[1] 3


标签: r list nan