> -Original Message-
> From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com]
> Sent: Friday, May 27, 2011 5:23 AM
> To: Albert-Jan Roskam
> Cc: William Dunlap; Marc Schwartz; R Mailing List
> Subject: Re: [R] NaN, Inf to NA
>
> On 11-05-27 4:27 AM, Albert-J
>> it here)
>>
>> ditch<- function(x) ifelse(is.infinite(x) | is.nan(x),
>> NA, x) df<- apply(df, 2, ditch)
>>
>>
>>
>>
>>
>> From: William
>> Dunlap
liam Dunlap
Cc: R Mailing List
Sent: Fri, May 27, 2011 12:57:01 AM
Subject: RE: [R] NaN, Inf to NA
I think the source of the OP's problem is that
while things like df>30 and is.na(df) return
a logical matrix with the dimensions of the
data.frame df, both is.infinite(df) and is.nan(df)
(a=c(NA, NaN, Inf, 1:3), b=c(2,NaN))
df[] <- lapply(df, function(x) ifelse(is.finite(x), x, NA))
KK
>
>
>
>
>
> From: William Dunlap
>
> Cc: R Mailing List
> Sent: Fri, May 27, 2011 12:57:01 AM
> Subject: RE: [R] NaN, Inf to NA
&g
27, 2011 12:57:01 AM
Subject: RE: [R] NaN, Inf to NA
I think the source of the OP's problem is that
while things like df>30 and is.na(df) return
a logical matrix with the dimensions of the
data.frame df, both is.infinite(df) and is.nan(df)
return a logical vector as long as the number
of c
Sent: Thursday, May 26, 2011 2:15 PM
> To: Albert-Jan Roskam
> Cc: R Mailing List
> Subject: Re: [R] NaN, Inf to NA
>
> On May 26, 2011, at 3:18 PM, Albert-Jan Roskam wrote:
>
> > Hi,
> >
> > I want to recode all Inf and NaN values to NA, but I;m
> surpris
On May 26, 2011, at 3:18 PM, Albert-Jan Roskam wrote:
> Hi,
>
> I want to recode all Inf and NaN values to NA, but I;m surprised to see the
> result of the following code. Could anybody enlighten me about this?
>
>> df <- data.frame(a=c(NA, NaN, Inf, 1:3))
>> df[is.infinite(df) | is.nan(df)] <
> df$a[is.infinite(df$a) | is.nan(df$a) ] <- NA
> df
a
1 NA
2 NA
3 NA
4 1
5 2
6 3
On 5/26/11 3:18 PM, "Albert-Jan Roskam" wrote:
>Hi,
>
>I want to recode all Inf and NaN values to NA, but I;m surprised to see
>the
>result of the following code. Could anybody enlighten me about this?
>
>>
Hi,
I want to recode all Inf and NaN values to NA, but I;m surprised to see the
result of the following code. Could anybody enlighten me about this?
> df <- data.frame(a=c(NA, NaN, Inf, 1:3))
> df[is.infinite(df) | is.nan(df)] <- NA
> df
a
1 NA
2 NaN
3 Inf
4 1
5 2
6 3
>
Thanks!
9 matches
Mail list logo