Glad it works. So far we seem to have at least three ways to do it. R is
amazing!
John Kane
Kingston ON Canada
> -Original Message-
> From: antony.akk...@ge.com
> Sent: Mon, 2 Jul 2012 06:04:03 -0700 (PDT)
> To: r-help@r-project.org
> Subject: Re: [R] Decrete value ch
Good. Its working fine.
Thank you John !
From: John Kane [via R]
[mailto:ml-node+s789695n4635113...@n4.nabble.com]
Sent: Monday, July 02, 2012 6:18 PM
To: Akkara, Antony (GE Energy, Non-GE)
Subject: Re: Decrete value check in a matrix
You are not asking for a Decrete [sic] (descrete) va
Hi,
Try this:
dat1<-read.table(text="
ABC XYZ
1 2.5
3.4 4
5 6
5.6 6.7
",sep="",header=TRUE)
dat1[dat1$ABC ==as.integer(dat1$ABC), "ABC_RESULT"]<-TRUE
dat1[dat1$XYZ== as.integer(dat1$XYZ),"XYZ_RESULT"]<-TRUE
dat1[is.na(dat1)]<-FALSE
dat
Need not to be that complicated:
> aa == round(aa)
nanb
[1,] TRUE FALSE
[2,] FALSE TRUE
[3,] TRUE TRUE
[4,] FALSE FALSE
> cbind(aa, Result = aa == round(aa))
na nb Result.na Result.nb
1 1.0 2.4 TRUE FALSE
2 3.4 4.0 FALSE TRUE
3 5.0 6.0 TRUE T
You are not asking for a Decrete [sic] (descrete) value check but rather if
the numbers are intergers.
Try this:
# from the ?is.integer help page
is.wholenumber <-
function(x, tol = .Machine$double.eps^0.5) abs(x - round(x)) < tol
aa <- data.frame( na = c( 1, 3.4, 5, 5.6), nb = c(2.4,
5 matches
Mail list logo