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.
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 dat1 ? ABC XYZ ABC_RESULT XYZ_RESULT 1 1.0 2.5?????? TRUE????? FALSE 2 3.4 4.0????? FALSE?????? TRUE 3 5.0 6.0?????? TRUE?????? TRUE 4 5.6 6.7????? FALSE????? FALSE A.K. ________________________________ From: "Akkara, Antony (GE Energy, Non-GE)" <Antony.Akkara at ge.com> To: arun <smartpink111 at yahoo.com> Sent: Monday, July 2, 2012 7:29 AM Subject: Decrete value check in a matrix Hi Arun, Can you please help me, Here i have a Data frame (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 solution fast. Its urgent thtz y. Antony.??
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!
Need not to be that complicated:> aa == round(aa)na nb [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 TRUE 4 5.6 6.7 FALSE FALSE Regards, Marc Schwartz On Jul 2, 2012, at 7:46 AM, John Kane wrote:> 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. >>
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.akkara at ge.com > Sent: Mon, 2 Jul 2012 06:04:03 -0700 (PDT) > To: r-help at r-project.org > Subject: Re: [R] Decrete value check in a matrix > > Good. Its working fine. > > Thank you John ! > > > > From: John Kane [via R] > [mailto:ml-node+s789695n4635113h41 at 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) 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: [hidden email] >> Sent: Mon, 2 Jul 2012 03:04:48 -0700 (PDT) >> To: [hidden email] >> 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! > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > > > ________________________________ > > If you reply to this email, your message will be added to the discussion > below: > > http://r.789695.n4.nabble.com/Decrete-value-check-in-a-matrix-tp4635090p > 4635113.html > > To unsubscribe from Decrete value check in a matrix, click here > <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscrib > e_by_code&node=4635090&code=YW50b255LmFra2FyYUBnZS5jb218NDYzNTA5MHwxNTUx > OTQzMDI5> . > NAML > <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_view > er&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.Bas > icNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.tem > plate.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml > -instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemai > l.naml> > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Decrete-value-check-in-a-matrix-tp4635090p4635118.html > Sent from the R help mailing list archive at Nabble.com. > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!