Shankar Lanke
2012-May-03 02:06 UTC
[R] Identifying the particular X or Y in a sorted list
Dear All, I have a data sets as shown below A (Patient ID ), B and C are the Concentration of drug in blood on day 1 and day 4, D is the difference in conc. To do this in R I have written a code as follows, identified the number of patients who have more concentration on day 4 . Here I want to identify specifically the patient ID (is he patient 1 or 2 or 5 and 7), whose concentration is more. How to write a code to get the list of A (patient ID whose difference is more on day 4). Data<-(myDf$B-myDf$C) sum(Data>0) A B CD (B-C) 1 14 10 4 2 12 7 5 3 11 15 -4 4 8 3 5 5 1 8 -7 I appreciate your help, thank you very much in advance. Regards [[alternative HTML version deleted]]
Hello, Shankar Lanke wrote> > Dear All, > > I have a data sets as shown below A (Patient ID ), B and C are the > Concentration of drug in blood on day 1 and day 4, D is the difference in > conc. To do this in R I have written a code as follows, identified the > number of patients who have more concentration on day 4 . Here I want to > identify specifically the patient ID (is he patient 1 or 2 or 5 and 7), > whose concentration is more. > How to write a code to get the list of A (patient ID whose difference is > more on day 4). > > Data<-(myDf$B-myDf$C) > sum(Data>0) > > A B CD (B-C) 1 14 10 4 2 12 7 5 3 11 15 -4 4 8 3 5 5 1 8 -7 > > I appreciate your help, thank you very much in advance. > > Regards > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@ 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 I understand it correctly, this should do it. x <- read.table(text=" A B C D 1 14 10 4 2 12 7 5 3 11 15 -4 4 8 3 5 5 1 8 -7 ", header=TRUE) which(x$D == max(x$D)) x$A[ which(x$D == max(x$D)) ] Or you can save the values of the which() function and use them when needed. Hope this helps, Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/Identifying-the-particular-X-or-Y-in-a-sorted-list-tp4605124p4606062.html Sent from the R help mailing list archive at Nabble.com.
Shankar Lanke
2012-May-03 14:29 UTC
[R] Identifying the particular X or Y in a sorted list
Dear All, I have a data sets as shown below A (Patient ID ), B and C are the Concentration of drug in blood on day 1 and day 4, D is the difference in conc. To do this in R I have written a code as follows, identified the number of patients who have more concentration on day 4 . Here I want to identify specifically the patient ID (is he patient 1 or 2 or 5 and 7), whose concentration is more. How to write a code to get the list of A (patient ID whose difference is more on day 4). Data<-(myDf$B-myDf$C) sum(Data>0) ABCD (B-C)1141042127531115-44835518-7 I appreciate your help, thank you very much in advance. Regards [[alternative HTML version deleted]]
You do not seem to have suppied either code nor data. Please supply both. John Kane Kingston ON Canada> -----Original Message----- > From: shankarlanke at gmail.com > Sent: Wed, 2 May 2012 22:06:54 -0400 > To: r-help at r-project.org > Subject: [R] Identifying the particular X or Y in a sorted list > > Dear All, > > I have a data sets as shown below A (Patient ID ), B and C are the > Concentration of drug in blood on day 1 and day 4, D is the difference in > conc. To do this in R I have written a code as follows, identified the > number of patients who have more concentration on day 4 . Here I want to > identify specifically the patient ID (is he patient 1 or 2 or 5 and 7), > whose concentration is more. > How to write a code to get the list of A (patient ID whose difference is > more on day 4). > > Data<-(myDf$B-myDf$C) > sum(Data>0) > > A B CD (B-C) 1 14 10 4 2 12 7 5 3 11 15 -4 4 8 3 5 5 1 8 -7 > > I appreciate your help, thank you very much in advance. > > Regards > > [[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.____________________________________________________________ GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails
I'm sorry, it's still not clear what you are doing but perhaps this is close? mydata <- data.frame( a = c(1, 2, 3, 4 , 5), b = c(7, 2, 3, 6, 9), c = c(4, 6, 9, 2, 5)) mydata$d <- mydata$b - mydata$c mydata subset(mydata, mydata$d ==max(mydata$d)) John Kane Kingston ON Canada -----Original Message----- From: shankarlanke at gmail.com Sent: Thu, 3 May 2012 14:14:17 -0400 To: jrkrideau at inbox.com Subject: Re: [R] Identifying the particular X or Y in a sorted list Dear All, Thank you very much in advance. I have a data sets as shown below A (Patient ID ), B and C are the Concentration of drug in blood on day 1 and day 4, D is the difference in conc. To do this in R I have written a code as follows, identified the number of patients who have more concentration on day 4 . Here I want to identify specifically the patient ID (is he patient 1 or 2 or 5 and 7), whose concentration is more. How to write a code to get the list of A (patient ID whose difference is more on day 4). A 1 2 3 4 5 B 7 2 3 6 9 C 4 6 9 2 5 (B-C) 3 -4 -6 4 4 DF1<-list(A,B,C) DF1 DF2<-(DF1$C-DF1$B) length(DF2) sum(DF2>0) #I want to subtract B from C to see and identify how many patients have greater concentrations and who are these patients (A). On Thu, May 3, 2012 at 12:15 PM, John Kane <[1]jrkrideau at inbox.com> wrote: You do not seem to have suppied either code nor data. Please supply both. John Kane Kingston ON Canada > -----Original Message----- > From: [2]shankarlanke at gmail.com > Sent: Wed, 2 May 2012 22:06:54 -0400 > To: [3]r-help at r-project.org > Subject: [R] Identifying the particular X or Y in a sorted list > > Dear All, > > I have a data sets as shown below A (Patient ID ), B and C are the > Concentration of drug in blood on day 1 and day 4, D is the difference in > conc. To do this in R I have written a code as follows, identified the > number of patients who have more concentration on day 4 . Here I want to > identify specifically the patient ID (is he patient 1 or 2 or 5 and 7), > whose concentration is more. > How to write a code to get the list of A (patient ID whose difference is > more on day 4). > > Data<-(myDf$B-myDf$C) > sum(Data>0) > > A B CD (B-C) 1 14 10 4 2 12 7 5 3 11 15 -4 4 8 3 5 5 1 8 -7 > > I appreciate your help, thank you very much in advance. > > Regards > > [[alternative HTML version deleted]] > > ______________________________________________ > [4]R-help at r-project.org mailing list > [5]https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > [6]http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ____________________________________________________________ GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at [7]http://www.inbox.com/smileys Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails -- Regards, Shankar Lanke Ph.D. Assistant Professor Department of Pharmaceutical Sciences College of Pharmacy The University of Findlay (C) 678-232-3567 (O) 419-434-5448 Fax# 419-434-4390 _________________________________________________________________ Free Online Photosharing - Share your photos online with your friends and family! Visit [8]http://www.inbox.com/photosharing to find out more! References 1. mailto:jrkrideau at inbox.com 2. mailto:shankarlanke at gmail.com 3. mailto:r-help at r-project.org 4. mailto:R-help at r-project.org 5. https://stat.ethz.ch/mailman/listinfo/r-help 6. http://www.R-project.org/posting-guide.html 7. http://www.inbox.com/smileys 8. http://www.inbox.com/photosharing
simply change the specification in the subset command to >0 John Kane Kingston ON Canada -----Original Message----- From: shankarlanke at gmail.com Sent: Thu, 3 May 2012 16:51:50 -0400 To: jrkrideau at inbox.com Subject: Re: [R] Identifying the particular X or Y in a sorted list Dear John, Thank you very much for your response, I appreciate your input. I am able to subtract the two columns, (B - C) , the subset information I need is how many "A"s and who are the "A". For example P,Q,R,S,T, persons earned $ 7, 2, 3, 6, 9 in 1 st month and $ 4, 6, 9, 2, 5 in 2nd month. I want to identify who earned more on 1st month + the difference (only if it is positive). In this case P,S,T earned $3,4,4, in 2nd month. mydata <- data.frame( a = c(1, 2, 3, 4 , 5), b = c(7, 2, 3, 6, 9), c c(4, 6, 9, 2, 5)) mydata$d <- mydata$b - mydata$c mydata subset(mydata, mydata$d ==max(mydata$d)) On Thu, May 3, 2012 at 2:47 PM, John Kane <[1]jrkrideau at inbox.com> wrote: I'm sorry, it's still not clear what you are doing but perhaps this is close? mydata <- data.frame( a = c(1, 2, 3, 4 , 5), b = c(7, 2, 3, 6, 9), c c(4, 6, 9, 2, 5)) mydata$d <- mydata$b - mydata$c mydata subset(mydata, mydata$d ==max(mydata$d)) John Kane Kingston ON Canada -----Original Message----- From: [2]shankarlanke at gmail.com Sent: Thu, 3 May 2012 14:14:17 -0400 To: [3]jrkrideau at inbox.com Subject: Re: [R] Identifying the particular X or Y in a sorted list Dear All, Thank you very much in advance. I have a data sets as shown below A (Patient ID ), B and C are the Concentration of drug in blood on day 1 and day 4, D is the difference in conc. To do this in R I have written a code as follows, identified the number of patients who have more concentration on day 4 . Here I want to identify specifically the patient ID (is he patient 1 or 2 or 5 and 7), whose concentration is more. How to write a code to get the list of A (patient ID whose difference is more on day 4). A 1 2 3 4 5 B 7 2 3 6 9 C 4 6 9 2 5 (B-C) 3 -4 -6 4 4 DF1<-list(A,B,C) DF1 DF2<-(DF1$C-DF1$B) length(DF2) sum(DF2>0) #I want to subtract B from C to see and identify how many patients have greater concentrations and who are these patients (A). On Thu, May 3, 2012 at 12:15 PM, John Kane <[4]jrkrideau at inbox.com> wrote: You do not seem to have suppied either code nor data. Please supply both. John Kane Kingston ON Canada > -----Original Message----- > From: [5]shankarlanke at gmail.com > Sent: Wed, 2 May 2012 22:06:54 -0400 > To: [6]r-help at r-project.org > Subject: [R] Identifying the particular X or Y in a sorted list > > Dear All, > > I have a data sets as shown below A (Patient ID ), B and C are the > Concentration of drug in blood on day 1 and day 4, D is the difference in > conc. To do this in R I have written a code as follows, identified the > number of patients who have more concentration on day 4 . Here I want to > identify specifically the patient ID (is he patient 1 or 2 or 5 and 7), > whose concentration is more. > How to write a code to get the list of A (patient ID whose difference is > more on day 4). > > Data<-(myDf$B-myDf$C) > sum(Data>0) > > A B CD (B-C) 1 14 10 4 2 12 7 5 3 11 15 -4 4 8 3 5 5 1 8 -7 > > I appreciate your help, thank you very much in advance. > > Regards > > [[alternative HTML version deleted]] > > ______________________________________________ > [7]R-help at r-project.org mailing list > [8]https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > [9]http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ____________________________________________________________ GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at [10]http://www.inbox.com/smileys Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails -- Regards, Shankar Lanke Ph.D. Assistant Professor Department of Pharmaceutical Sciences College of Pharmacy The University of Findlay (C) [11]678-232-3567 (O) [12]419-434-5448 Fax# [13]419-434-4390 _________________________________________________________________ Free Online Photosharing - Share your photos online with your friends and family! Visit [14]http://www.inbox.com/photosharing to find out more! -- Regards, Shankar Lanke Ph.D. Assistant Professor Department of Pharmaceutical Sciences College of Pharmacy The University of Findlay (C) 678-232-3567 (O) 419-434-5448 Fax# 419-434-4390 _________________________________________________________________ [15]3D Marine Aquarium Screensaver Preview Free 3D Marine Aquarium Screensaver Watch dolphins, sharks & orcas on your desktop! Check it out at [16]www.inbox.com/marineaquarium References 1. mailto:jrkrideau at inbox.com 2. mailto:shankarlanke at gmail.com 3. mailto:jrkrideau at inbox.com 4. mailto:jrkrideau at inbox.com 5. mailto:shankarlanke at gmail.com 6. mailto:r-help at r-project.org 7. mailto:R-help at r-project.org 8. https://stat.ethz.ch/mailman/listinfo/r-help 9. http://www.R-project.org/posting-guide.html 10. http://www.inbox.com/smileys 11. tel:678-232-3567 12. tel:419-434-5448 13. tel:419-434-4390 14. http://www.inbox.com/photosharing 15. http://www.inbox.com/marineaquarium 16. http://www.inbox.com/marineaquarium