-1

I'm very new to R and currently working through data from my lab. I have a dataframe with a good amount of variables- two of these variables are Sample and Time. Each sample records a maximum of 10 minutes of observations, then restarts at 0 again for the next sample. I.e., sample 1 correctly displays the timestamps from 0 minutes to 10 minutes. However, upon going above 10 minutes of observations, the Time column will display 0, and the Sample column will display 2. Therefore, each time value in sample 2 observations should be the time displayed plus 10, each time value in sample 3 should be the time displayed plus 20, etc etc. What would be the best way to go about this? Sorry again if I don't have any of the jargon down, I just started learning r.

enter image description here

Phil
  • 7,287
  • 3
  • 36
  • 66
johnny2554
  • 33
  • 4
  • 1
    Could you provide a [minimum reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) of your data and some example output? – Rory S Jun 11 '21 at 19:34
  • Added a picture of the dataset, specifically when it switches from sample 1 to sample 2 – johnny2554 Jun 11 '21 at 20:30

1 Answers1

0

Without knowing for sure where the column that starts with 9.314... I cannot give an exact answer.

Is there a way for you to add something like this:

df$Time <- df$Time + (df$Sample - 1) * 10

My idea is to take the Time column and add (1 - 1) * 10 = 0 for Sample 1 (2 - 1) * 10 = 10 for Sample 2 etc

Indescribled
  • 320
  • 1
  • 10