-2

I am very new to R and am trying to answer a "simple" question. I have a DataFrame of isolates and their optical densities (OD) over time. I am looking for the point that the OD's double from the start point.

Simplified Data Frame

Time (mins)   R8-5081   R8-5088 R8-5095
0              0.766    0.895   0.623
15             0.531    0.593   0.436
30             0.531    0.581   0.408
45             0.522    0.593   0.407
60             0.52     0.6     0.409
75             0.527    0.612   0.416
90             0.527    0.616   0.416

I want the time at which the OD for R8-5081 becomes 1.06 (the first row where time = 0 is usually not the true value).

It is possible to do it in Excel, what would be the R style of approach?

Aj Taylor
  • 7
  • 2

2 Answers2

0

You should be including reproducible code with your question so we can test on your data. That said, I think this should work.

min(which(df$`R8-5081` >= 2 * df$`R8-5081`[2]))
AaronT86
  • 53
  • 4
  • I have no idea how to include "reproducible" code, honestly. As I said, I'm too new to coding in general to know what to do. That's why I'm looking here to see what I should be doing or where to go ): – Aj Taylor Jul 31 '17 at 21:14
  • https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example This link is great for describing it. Basically you write some short code so we can copy/paste into R, hit run, and work with your sample data. – AaronT86 Jul 31 '17 at 21:19
  • Do either of the answers provided give you what you need? If so, could you mark one of them as correct? – AaronT86 Aug 02 '17 at 18:59
  • Neither did, actually. I was able to find out what to do in Excel with use of the code `=CELL("row",INDEX(Sheet1!C4:C98,MATCH(TRUE,Sheet1!C4:C98>(Sheet1!C4*2),0)))` The R code would provide 0's reported back or no way to tell what occurred. – Aj Taylor Aug 02 '17 at 19:48
0

Following code will extract all row(s) where data point doubles:

od[which(od$R8.5081 == 2*od$R8.5081[2]), ]
od[which(od$R8.5088 == 2*od$R8.5088[2]), ]
od[which(od$R8.5095 == 2*od$R8.5095[2]), ]

Here, 'od' is data frame that contains the data points. (your excel/csv that can be read and stored in this variable)

If desired output is only first row where OD doubles, then;

od[min(which(od$R8.5081 == (2 * od$R8.5081[2]))),]
od[min(which(od$R8.5088 == (2 * od$R8.5088[2]))),]
od[min(which(od$R8.5095 == (2 * od$R8.5095[2]))),]
Sagar
  • 2,778
  • 1
  • 8
  • 16