[R] sorting/grouping/classification problem?

Bart Joosen bartjoosen at hotmail.com
Thu Jan 24 21:43:27 CET 2013


dat3 is the dataframe where there are some rrt values merged, which is actually the problem: how on Earth discide which rows van be merged....

Thanks for your input!

Bart

-----Original Message-----

From: arun
Sent: 24 Jan 2013 20:18:28 GMT
To: Bart Joosen
Cc: R help
Subject: Re: [R] sorting/grouping/classification problem?

HI,

If I understand your question, "dat3" is not you wanted.

Is  it something like this you wanted?
library(reshape2)
 dcast(dat,rrt~Mnd,value.var="Result")
#   rrt   0   3    6    9
#1 0.35  NA  NA 0.05   NA
#2 0.36  NA  NA   NA 0.06
#3 0.44  NA  NA 0.40   NA
#4 0.45 0.1 0.2   NA 0.60
#5 0.46  NA  NA 1.20   NA
#6 0.48 0.3 0.6   NA 1.80
#7 1.21  NA  NA 0.45   NA
#8 1.22  NA 0.4   NA 0.50
#9 1.24 0.5  NA   NA   NA
A.K.




----- Original Message -----
From: Bart Joosen <bartjoosen at hotmail.com>
To: r-help <r-help at r-project.org>
Cc:
Sent: Thursday, January 24, 2013 2:31 PM
Subject: [R] sorting/grouping/classification problem?


Hi,


I'm a database admin for a database which manage chromatographic results of products during stability studies.
I use R for the reporting of the results in MS Word through R2wd.


But now I think I need your help:
suppose we have the following data frame:


   ID  rrt Mnd Result
1 0.45   0   0.10
1 0.48   0   0.30
1 1.24   0   0.50
2 0.45   3   0.20
2 0.48   3   0.60
2 1.22   3   0.40
3 0.35   6   0.05
3 0.44   6   0.40
3 0.46   6   1.20
3 1.21   6   0.45
4 0.36   9   0.06
4 0.45   9   0.60
4 0.48   9   1.80
4 1.22   9   0.50



ID is the database ID, rrt is an identifier for the result, Mnd is the timepoint of analysis and Result is... the result of the test.
What I need is this dataframe in a wide format (which I managed with dat2 <- as.data.frame(tapply(dat$Result,list(rrt=dat$rrt,Mnd=dat$Mnd), function(x) paste(x[x!=""],collapse="/"))) )
But as you can see, rrt is not an exact identifier for the result.

Sometimes rrt for 0 Mnd is 0.45, but at 6 Mnd the rrt is 0.44.
Now I need the results to align so that one can easily see how rrt x is evolving within the Mnd time points.
I tried with different rounding procedures (round every 0.02, check that no results are discarded this way, and check for alignment), but nothing seems to make some sense.
Also tried checking the highest results in each Mnd, align these, determine correction factors for the rrt for all the other rrts, ...


Some results will follow a trend (like rrt 0.45), some will remain more or less stable.
But NEVER rrt will switch i with each other!




Ultimately I need to update in the db, so I need a list/dataframe with the ID, the original rrt and the adjusted rrt (maybe the first occuring rrt, or the mean of the rrts, doesn't matter).




Any ideas about which algorithms can be used? I searched on pubmed, but couldn't find anything




Thanks


Bart


PS: to get the data:


dat <-
structure(list(ID = c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
4L, 4L, 4L, 4L), rrt = c(0.45, 0.48, 1.24, 0.45, 0.48, 1.22,
0.35, 0.44, 0.46, 1.21, 0.36, 0.45, 0.48, 1.22), Mnd = c(0L,
0L, 0L, 3L, 3L, 3L, 6L, 6L, 6L, 6L, 9L, 9L, 9L, 9L), Result = c(0.1,
0.3, 0.5, 0.2, 0.6, 0.4, 0.05, 0.4, 1.2, 0.45, 0.06, 0.6, 1.8,
0.5)), .Names = c("ID", "rrt", "Mnd", "Result"), class = "data.frame", row.names = c(NA,
-14L))



resulting dataframe:
dat3 <-
structure(list(Time = c(0.355, 0.45, 0.48, 1.22), `0` = c(NA,
0.1, 0.3, 0.5), `3` = c(NA, 0.2, 0.6, 0.4), `6` = c(0.05, 0.4,
1.2, 0.45), `9` = c(0.06, 0.6, 1.8, 0.5)), .Names = c("Time",
"0", "3", "6", "9"), class = "data.frame", row.names = c(NA,
-4L))




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



More information about the R-help mailing list