Hi, Here i have been a matrix like this, *NAME AGE PALCE TRUE/FALSE* ABC 20 INDIA XYZ 30 FRANCE PQR 40 USA MNO 30 KENIYA DEF 25 AUSTRALIA Here,* TRUE/FALSE* Column containing empty values. So my requirement what is , need to change all the *TRUE/FALSE *column value into "*TRUE*" where *AGE = 30*. Note :- i *dont want* to use* any loop *and do. Main intension is avoid loop,bcz there is a bulk of data. Final Matrix should be like this *NAME AGE PALCE TRUE/FALSE* ABC 20 INDIA XYZ 30 FRANCE TRUE PQR 40 USA MNO 30 KENIYA TRUE DEF 25 AUSTRALIA Immediate Help Requied. Your, Antony. -- View this message in context: http://r.789695.n4.nabble.com/Hash-Table-Select-and-Change-Data-iniside-Matrix-tp4631312.html Sent from the R help mailing list archive at Nabble.com.
Hash Table - Select and Change Data iniside Matrix
10 messages · Rantony, Jeff Newmiller, arun +2 more
There aren't "empty" values in R..... nor is it likely you have a matrix of this form, but perhaps a data frame. Perhaps this works for you, If "dat" is the name of your data.frame, dat[dat$AGE == 30,"TRUE/FALSE"] <- TRUE Next time do use dput() to give a reproducible example of your data -- if it's very large, just limit it to the first 30 rows or so with dput(head(dats, 30)) Michael
On Fri, May 25, 2012 at 9:43 AM, Rantony <antony.akkara at ge.com> wrote:
Hi, Here i have been a matrix like this, *NAME ? ?AGE ? PALCE ? ? ? ? ? ? ? ?TRUE/FALSE* ABC ? ? ? ? 20 ? ? ?INDIA XYZ ? ? ? ? 30 ? ? ? FRANCE PQR ? ? ? ?40 ? ? ? USA MNO ? ? 30 ? ? ? ?KENIYA DEF ? ? ? ?25 ? ? ? ?AUSTRALIA Here,* TRUE/FALSE* ?Column containing empty values. So my requirement what is , need to change all the *TRUE/FALSE *column value into "*TRUE*" where *AGE = 30*. Note :- i *dont want* to use* any loop *and do. Main intension is avoid loop,bcz there is a bulk of data. Final Matrix should be like this *NAME ? ?AGE ? PALCE ? ? ? ? ? ? ? ?TRUE/FALSE* ABC ? ? ? ? 20 ? ? ?INDIA XYZ ? ? ? ? 30 ? ? ? FRANCE ? ? ? ? ? ? ? ? ? ? TRUE PQR ? ? ? ?40 ? ? ? USA MNO ? ? 30 ? ? ? ?KENIYA ? ? ? ? ? ? ? ? ? ? ?TRUE DEF ? ? ? ?25 ? ? ? ?AUSTRALIA Immediate Help Requied. Your, Antony. -- View this message in context: http://r.789695.n4.nabble.com/Hash-Table-Select-and-Change-Data-iniside-Matrix-tp4631312.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ 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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120525/73299399/attachment.pl>
Read help for the ifelse function. Type ?ifelse at the command line.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
Rantony <antony.akkara at ge.com> wrote:
Hi,
Here i have been a matrix like this,
*NAME AGE PALCE TRUE/FALSE*
ABC 20 INDIA
XYZ 30 FRANCE
PQR 40 USA
MNO 30 KENIYA
DEF 25 AUSTRALIA
Here,* TRUE/FALSE* Column containing empty values.
So my requirement what is , need to change all the *TRUE/FALSE *column
value
into "*TRUE*" where *AGE = 30*.
Note :- i *dont want* to use* any loop *and do. Main intension is avoid
loop,bcz there is a bulk of data.
Final Matrix should be like this
*NAME AGE PALCE TRUE/FALSE*
ABC 20 INDIA
XYZ 30 FRANCE TRUE
PQR 40 USA
MNO 30 KENIYA TRUE
DEF 25 AUSTRALIA
Immediate Help Requied.
Your,
Antony.
--
View this message in context:
http://r.789695.n4.nabble.com/Hash-Table-Select-and-Change-Data-iniside-Matrix-tp4631312.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________ 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.
Hi Antony, Try this, da<-read.table(text="NAME??? AGE??????? PLACE??? ABC??????? 20????? INDIA XYZ??????? 30????? FRANCE PQR??????? 40????? USA MNO??????? 30?????? KENYA DEF??????? 25??????? AUSTRALIA", header=TRUE,stringsAsFactors=FALSE)
da2<-function(x){
?if(x==30) ?TRUE ?else ?FALSE ?} da3<-sapply(da$AGE,da2) TRUE_FALSE<-da3 da1<-data.frame(da,TRUE_FALSE) ?da1 ? NAME AGE???? PLACE TRUE_FALSE 1? ABC? 20???? INDIA????? FALSE 2? XYZ? 30??? FRANCE?????? TRUE 3? PQR? 40?????? USA????? FALSE 4? MNO? 30???? KENYA?????? TRUE 5? DEF? 25 AUSTRALIA????? FALSE A.K. ----- Original Message ----- From: Jeff Newmiller <jdnewmil at dcn.davis.ca.us> To: Rantony <antony.akkara at ge.com>; r-help at r-project.org Cc: Sent: Friday, May 25, 2012 10:25 AM Subject: Re: [R] Hash Table - Select and Change Data iniside Matrix Read help for the ifelse function. Type ?ifelse at the command line. --------------------------------------------------------------------------- Jeff Newmiller? ? ? ? ? ? ? ? ? ? ? ? The? ? .....? ? ? .....? Go Live... DCN:<jdnewmil at dcn.davis.ca.us>? ? ? ? Basics: ##.#.? ? ? ##.#.? Live Go... ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Live:? OO#.. Dead: OO#..? Playing Research Engineer (Solar/Batteries? ? ? ? ? ? O.O#.? ? ? #.O#.? with /Software/Embedded Controllers)? ? ? ? ? ? ? .OO#.? ? ? .OO#.? rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity.
Rantony <antony.akkara at ge.com> wrote:
Hi, Here i have been a matrix like this, *NAME? ? AGE? PALCE? ? ? ? ? ? ? ? TRUE/FALSE* ABC? ? ? ? 20? ? ? INDIA XYZ? ? ? ? 30? ? ? FRANCE PQR? ? ? ? 40? ? ? USA MNO? ? 30? ? ? ? KENIYA DEF? ? ? ? 25? ? ? ? AUSTRALIA Here,* TRUE/FALSE*? Column containing empty values. So my requirement what is , need to change all the *TRUE/FALSE *column value into "*TRUE*" where *AGE = 30*. Note :- i *dont want* to use* any loop *and do. Main intension is avoid loop,bcz there is a bulk of data. Final Matrix should be like this *NAME? ? AGE? PALCE? ? ? ? ? ? ? ? TRUE/FALSE* ABC? ? ? ? 20? ? ? INDIA? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? XYZ? ? ? ? 30? ? ? FRANCE? ? ? ? ? ? ? ? ? ? TRUE PQR? ? ? ? 40? ? ? USA? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? MNO? ? 30? ? ? ? KENIYA? ? ? ? ? ? ? ? ? ? ? TRUE DEF? ? ? ? 25? ? ? ? AUSTRALIA Immediate Help Requied.? Your, Antony. -- View this message in context: http://r.789695.n4.nabble.com/Hash-Table-Select-and-Change-Data-iniside-Matrix-tp4631312.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ 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.
______________________________________________ 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.
Well... (inline)
On Fri, May 25, 2012 at 11:19 AM, arun <smartpink111 at yahoo.com> wrote:
Hi Antony, Try this, da<-read.table(text="NAME??? AGE??????? PLACE ABC??????? 20????? INDIA XYZ??????? 30????? FRANCE PQR??????? 40????? USA MNO??????? 30?????? KENYA DEF??????? 25??????? AUSTRALIA", header=TRUE,stringsAsFactors=FALSE)
da2<-function(x){
?if(x==30)
NO! if is **not** vectorized; this should throw a warning.
?TRUE ?else ?FALSE ?} da3<-sapply(da$AGE,da2) TRUE_FALSE<-da3 da1<-data.frame(da,TRUE_FALSE)
This is poor R programming practice on several different levels. By adhering to the R paradigm of vectorization, it can be made way simpler and more transparent. Also note that "TRUE/FALSE" is potentially problematic as a column name; try to adhere to standard R names to avoid "infelicities." Anyway, simply: da$newColumn <- da$AGE ==30 or, alternatively, da$newColumn <- with(da, AGE == 30) Cheers, Bert
?da1 ? NAME AGE???? PLACE TRUE_FALSE 1? ABC? 20???? INDIA????? FALSE 2? XYZ? 30??? FRANCE?????? TRUE 3? PQR? 40?????? USA????? FALSE 4? MNO? 30???? KENYA?????? TRUE 5? DEF? 25 AUSTRALIA????? FALSE A.K. ----- Original Message ----- From: Jeff Newmiller <jdnewmil at dcn.davis.ca.us> To: Rantony <antony.akkara at ge.com>; r-help at r-project.org Cc: Sent: Friday, May 25, 2012 10:25 AM Subject: Re: [R] Hash Table - Select and Change Data iniside Matrix Read help for the ifelse function. Type ?ifelse at the command line. --------------------------------------------------------------------------- Jeff Newmiller? ? ? ? ? ? ? ? ? ? ? ? The? ? ?.....? ? ? ?.....? Go Live... DCN:<jdnewmil at dcn.davis.ca.us>? ? ? ? Basics: ##.#.? ? ? ?##.#.? Live Go... ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Live:? ?OO#.. Dead: OO#..? Playing Research Engineer (Solar/Batteries? ? ? ? ? ? O.O#.? ? ? ?#.O#.? with /Software/Embedded Controllers)? ? ? ? ? ? ? ?.OO#.? ? ? ?.OO#.? rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. Rantony <antony.akkara at ge.com> wrote:
Hi, Here i have been a matrix like this, *NAME? ? AGE? ?PALCE? ? ? ? ? ? ? ? TRUE/FALSE* ABC? ? ? ? ?20? ? ? INDIA XYZ? ? ? ? ?30? ? ? ?FRANCE PQR? ? ? ? 40? ? ? ?USA MNO? ? ?30? ? ? ? KENIYA DEF? ? ? ? 25? ? ? ? AUSTRALIA Here,* TRUE/FALSE*? Column containing empty values. So my requirement what is , need to change all the *TRUE/FALSE *column value into "*TRUE*" where *AGE = 30*. Note :- i *dont want* to use* any loop *and do. Main intension is avoid loop,bcz there is a bulk of data. Final Matrix should be like this *NAME? ? AGE? ?PALCE? ? ? ? ? ? ? ? TRUE/FALSE* ABC? ? ? ? ?20? ? ? INDIA XYZ? ? ? ? ?30? ? ? ?FRANCE? ? ? ? ? ? ? ? ? ? ?TRUE PQR? ? ? ? 40? ? ? ?USA MNO? ? ?30? ? ? ? KENIYA? ? ? ? ? ? ? ? ? ? ? TRUE DEF? ? ? ? 25? ? ? ? AUSTRALIA Immediate Help Requied. Your, Antony. -- View this message in context: http://r.789695.n4.nabble.com/Hash-Table-Select-and-Change-Data-iniside-Matrix-tp4631312.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ 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.
______________________________________________ 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. ______________________________________________ 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.
Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
2 days later
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120528/d5644e79/attachment.pl>
Greater than or equal to is simply >= like most languages. For more complicated questions, simply combine booleans: E.g., between 5 and 25 with(dat, (AGE < 25) & (AGE > 5)) and so on. Michael
On Mon, May 28, 2012 at 9:34 AM, Rantony <antony.akkara at ge.com> wrote:
Hi Michel, More than equal to function, how can I use other function ?, For example :- Age between Age Greater Than or Equal to like that ?. How ? From: Michael Weylandt [via R] [mailto:ml-node+s789695n4631319h27 at n4.nabble.com] Sent: Friday, May 25, 2012 7:48 PM To: Akkara, Antony (GE Energy, Non-GE) Subject: Re: Hash Table - Select and Change Data iniside Matrix There aren't "empty" values in R..... nor is it likely you have a matrix of this form, but perhaps a data frame. Perhaps this works for you, If "dat" is the name of your data.frame, dat[dat$AGE == 30,"TRUE/FALSE"] <- TRUE Next time do use dput() to give a reproducible example of your data -- if it's very large, just limit it to the first 30 rows or so with dput(head(dats, 30)) Michael On Fri, May 25, 2012 at 9:43 AM, Rantony <[hidden email]> wrote:
Hi, Here i have been a matrix like this, *NAME ? ?AGE ? PALCE ? ? ? ? ? ? ? ?TRUE/FALSE* ABC ? ? ? ? 20 ? ? ?INDIA XYZ ? ? ? ? 30 ? ? ? FRANCE PQR ? ? ? ?40 ? ? ? USA MNO ? ? 30 ? ? ? ?KENIYA DEF ? ? ? ?25 ? ? ? ?AUSTRALIA Here,* TRUE/FALSE* ?Column containing empty values. So my requirement what is , need to change all the *TRUE/FALSE *column value into "*TRUE*" where *AGE = 30*. Note :- i *dont want* to use* any loop *and do. Main intension is avoid loop,bcz there is a bulk of data. Final Matrix should be like this *NAME ? ?AGE ? PALCE ? ? ? ? ? ? ? ?TRUE/FALSE* ABC ? ? ? ? 20 ? ? ?INDIA XYZ ? ? ? ? 30 ? ? ? FRANCE ? ? ? ? ? ? ? ? ? ? TRUE PQR ? ? ? ?40 ? ? ? USA MNO ? ? 30 ? ? ? ?KENIYA ? ? ? ? ? ? ? ? ? ? ?TRUE DEF ? ? ? ?25 ? ? ? ?AUSTRALIA Immediate Help Requied. Your, Antony. -- View this message in context: http://r.789695.n4.nabble.com/Hash-Table-Select-and-Change-Data-iniside-Matrix-tp4631312.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ [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.
______________________________________________ [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/Hash-Table-Select-and-Change-Data-iniside-Matrix-tp4631312p4631319.html To unsubscribe from Hash Table - Select and Change Data iniside Matrix, click here <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4631312&code=YW50b255LmFra2FyYUBnZS5jb218NDYzMTMxMnwxNTUxOTQzMDI5> . NAML <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> -- View this message in context: http://r.789695.n4.nabble.com/Hash-Table-Select-and-Change-Data-iniside-Matrix-tp4631312p4631579.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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120529/e462d423/attachment.pl>
It would behoove you to read some introductory materials -- use
help.start() to get be provided with the standard "An Introduction to
R."
More generally, the help system can be accessed by typing help("name")
or, as a shortcut, ?name. In your case, help("&") would lead to the
correct answer.
The OR operator follows the standard of most programming languages --
the "pipe" operator, | . On my keyboard (mac) it's typed by pressing
shift+\ -- I forget where it is for a PC.
Michael
On Tue, May 29, 2012 at 5:40 AM, Rantony <antony.akkara at ge.com> wrote:
Hi Michel, In this function, I want to apply ?OR? operator instead of ?&? Condition. dat[dat$AGE<=40 & da$AGE>=30,"TRUE/FALSE"]<-TRUE How it is possible ? - ? ? ? ? ?Thanks Antony