[R] Decrete value check in a matrix

John Kane jrkrideau at inbox.com
Mon Jul 2 14:46:05 CEST 2012


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, 4, 6, 6.7))
ww  <- data.frame(  is.wholenumber(aa))
cbind(aa, ww)

John Kane
Kingston ON Canada


> -----Original Message-----
> From: antony.akkara at ge.com
> Sent: Mon, 2 Jul 2012 03:04:48 -0700 (PDT)
> To: r-help at r-project.org
> Subject: [R] Decrete value check in a matrix
> 
> Hi All,
> 
> Here i have an Dataframe (or) Matrix like this,
> 
> MyMatrix <-
> ABC          XYZ
> ------        -------
> 1              2.5
> 3.4           4
> 5              6
> 5.6          6.7
> 
> Here i need to check each column value having decrete value or not ?.
> If that particular coulmn-value having decrete value, then the result
> should
> be
> TRUE/FALSE respectively in the result column.
> Finally, i need to get the result as  Dataframe (or) Matrix form like
> this
> 
> ABC          XYZ      ABC_RESULT               XYZ_RESULT
> ------        -------     --------------------
> --------------------
> 1              2.5                 TRUE                       FALSE
> 3.4           4                    FALSE                     TRUE
> 5              6                    TRUE                        TRUE
> 5.6          6.7                  FALSE                     FALSE
> 
> - Can any one help me fast ?
> 
> Antony.
>

____________________________________________________________
Receive Notifications of Incoming Messages
Easily monitor multiple email accounts & access them with a click.
Visit http://www.inbox.com/notifier and check it out!



More information about the R-help mailing list