You could define a simple function to detect whether a value is within a
given range.  For example,

inrange <- function(vec, range) {
!is.na(vec) & vec >= range[1] & vec <= range[2]
 }
x <- 1:30
inrange(x, c(5, 20))

If you wanted to apply this function to all three columns at once, you
could use apply().  For example,
apply(data_log, 2, inrange)

Jean



On Thu, Jun 26, 2014 at 11:17 AM, VINCENT DEAN BOYCE <
vincentdeanboyce@gmail.com> wrote:

> Hello,
>
> Using R,  I've loaded a .cvs file comprised of several hundred rows and 3
> columns of data. The data within maps the output of a triaxial
> accelerometer, a sensor which measures an object's acceleration along the
> x,y and z axes. The data for each respective column sequentially
> oscillates, and ranges numerically from 100 to 500.
>
> I want create a function that parses the data and detects patterns across
> the three columns.
>
> For instance, I would like to detect instances when the values for the x,y
> and z columns equal 150, 200, 300 respectively. Additionally, when a match
> is detected, I would like to know how many times the pattern appears.
>
> I have been successful using str_detect to provide a Boolean, however it
> seems to only work on a single vector, i.e, "400" , not a range of values
> i.e "400 - 450". See below:
>
>
> # this works
> > vals <- str_detect (string = data_log$x_reading, pattern = "400")
>
> # this also works, but doesn't detect the particular range, rather the
> existence of the numbers
> > vals <- str_detect (string = data_log$x_reading, pattern = "[400-450]")
>
> Also, it appears that I can only apply it to a single column, not to all
> three columns. However I may be mistaken.
>
> Any advice on my current approach or alternativea I should consider is
> greatly appreciated.
>
> Many thanks,
>
> Vincent
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]

