-1

This question has a couple of parts :

  1. I have a subset of the data where events happen in my data and I would like to create snapshot of the rows around those events, specifically I would like to get the 5 rows before the events and the 4 rows after.
  2. Then put the different snapshots into a matrix in so I can compare the different events to one another. Any help with either part would be greatly appreciated.
Mousa Alfhaily
  • 1,260
  • 3
  • 20
  • 38
Chuck
  • 13
  • 1
  • Can you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? – Julian Zucker Aug 22 '17 at 16:47
  • 1
    The data I am working with is time series data from a motor engine. The events are when the engine speed goes from zero to any other number positive or negative. The data set is large with each file having 60,000 observations in 27 columns. With there being about 500 events with the one file I'm working with right now. I'm trying to see how the engine behaves normally when it starts. – Chuck Aug 22 '17 at 17:07

1 Answers1

0

Considering I have no idea what your "event" is, my event for this example is the data is equal to 10

#Example Data
Row<-(1:20)
Data<-(1:20)

Df<-data.frame(Rows,Data)

#Sub Data based on conditon =10
subdata <- Df[apply(Df[,1:2] == 10, 1, all),]

#Find Row where event happened
OrginPoint<-subdata[1,1]

#Set ranges bsed on event 
LowRange<-OrginPoint-5
HighRange<-OrginPoint+4

#Subset Data -5 rows for orign and +4 rows from orgin
DataRange1<-Df[LowRange:HighRange,1:2]
Chabo
  • 2,842
  • 3
  • 17
  • 32
  • The data I am working with is time series data from a motor engine. The events are when the engine speed goes from zero to any other number positive or negative. The data set is large with each file having 60,000 observations in 27 columns. With there being about 500 events with the one file I'm working with right now. I'm trying to see how the engine behaves normally when it starts. – Chuck Aug 22 '17 at 17:34
  • You would need to implement this general idea into a loop then to run through all your rows. You can look at all the columns by setting the Df[,1:27], and a time series shouldn't complicate things much more. The main thing you need to do is figure out how to check for that change to trigger the sub-setting. I will update my answer later in the day when I get the chance. Also update your question with the info you just gave me, that will make it much more understandable. Good Luck! – Chabo Aug 22 '17 at 17:57
  • Events only occur in one column but I'm trying to get data from the howl row. – Chuck Aug 22 '17 at 19:20