Skip to content

Decrete value check in a matrix

5 messages · Marc Schwartz, Rantony, John Kane

#
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.

--
View this message in context: http://r.789695.n4.nabble.com/Decrete-value-check-in-a-matrix-tp4635090.html
Sent from the R help mailing list archive at Nabble.com.
#
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
____________________________________________________________
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!
#
Need not to be that complicated:
na    nb
[1,]  TRUE FALSE
[2,] FALSE  TRUE
[3,]  TRUE  TRUE
[4,] FALSE FALSE
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       TRUE
4 5.6 6.7      FALSE      FALSE


Regards,

Marc Schwartz
On Jul 2, 2012, at 7:46 AM, John Kane wrote:

            
#
Glad it works.  So far we seem to have at least three ways to do it.  R is amazing!

John Kane
Kingston ON Canada
____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!