Reputation: 1
I have a quite special case with a dataset and what I want to do with it.To make it comprehensive I have to give a brief description of the background:
I have a sensor producing data, which needs maintenance every-now-and-then. Between every maintenance the data produced has a decreasing trend which I want to get rid of, and since maintenance is carried out quite often, I want to automate this procedure. The sensor is turned off when carrying out maintenance but the telemetry system still produces readings marked with " * ". Therefore the subsets of data to be detrended can be easily spotted between batches of "*" readings. I have been (unsuccessfully) trying to create a vector (on which I can then carry out a detrending procedure) with this data by selecting the desired values by looping through the data using conditional statements. To begin selecting the values I used to following statement:
if((tryp[i-2,2]="*")&(tryp[i-1,2]="*")&(tryp[i,2]!="*"))
and to finish the selection (exit the loop):
if((tryp[i-2,2]!="*")&(tryp[i-1,2]!="*")&(tryp[i,2]="*"))
However, this last statement gives an error of "argument is of length zero" and the first statement doesn't seem to be working properly either.
This is how the data looks like
So for example, one subset of data that I would like to select for de-trending is between data points 9686 and 9690. Obviously this is very small subset, but it shows well what I am trying to communicate.
I would really appreciate if someone could let me know about an elegant way of doing this, including anything way different from what I was trying to do originally.
Many thanks!
Upvotes: 0
Views: 28
Reputation: 494
library(dplyr)
my_df <- data.frame(a = LETTERS[1:10], b = c('+','*','*', '+', '*', '*', '+', '+', '*', '*'))
my_df %>% filter(b != '*')
Suppose the '+'-signs are your data points, you can easily get rid of the '*'-signs with filtering the rows which does not contain it.
And of course a solution without the dplyr
-package:
my_df[which(my_df$b!='*'),]
Upvotes: 1