[R] Operating on the value from row i and row i+1

Jaiprasart, Pharavee (HSC) pharavee-jaiprasart at ouhsc.edu
Thu Aug 14 17:07:33 CEST 2014


Hi all,



I'd like to make a step plot of Time vs Response graph.

This is the example of my data frame - the real data frame has more than a thousand rows.



Time          Duration of infusion           Infusion Rate            Response               Subtype

0                         3                                                     2                         5                                     0

3                         6                                                     3                         6                                     0

9                         6                                                     4                         4                                     0



I cannot just use type = c("s") for this because I also want to use the value of the in between time for further calculation too (If I ask the program for Response of time == 4, I want it to return "6").



The way I think the script should work is that:



For all rows that has subtype ==0, if time is between the value of row /i/ and /i+1/ (e.g. row 1 and 2 which is 0-3), make a new column "Dummy" and return the value of row /i/ from the Response column (e.g. 5 in this

example) , and do these for all rows (e.g. any time between row 2 and 3 which is 3-9, make a new column and return 6). Then I can say if Time>0 (value in column1) and <3 (value from column 1+2), y = value in Dummy



Is there any way to do this in R?



Thanks!

Pharavee


	[[alternative HTML version deleted]]



More information about the R-help mailing list