[R] Identifying the particular X or Y in a sorted list
Rui Barradas
ruipbarradas at sapo.pt
Thu May 3 15:50:29 CEST 2012
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.
More information about the R-help
mailing list