# [R] Stringr / Regular Expressions advice

arun smartpink111 at yahoo.com
Fri Jun 27 05:00:51 CEST 2014

```
Hi,
May be you can use ?cut or ?findInterval for the range

250, 300, 350
100, 350, 100
400, 250, 300
200, 450, 200
150, 501, 300
sapply(dat1, findInterval, c(400,500))==1
#        V1    V2    V3
#[1,] FALSE FALSE FALSE
#[2,] FALSE FALSE FALSE
#[3,] FALSE FALSE FALSE
#[4,]  TRUE FALSE FALSE
#[5,] FALSE  TRUE FALSE
#[6,] FALSE FALSE FALSE
#[7,] FALSE FALSE FALSE

A.K.

On Thursday, June 26, 2014 4:11 PM, VINCENT DEAN BOYCE <vincentdeanboyce at 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 at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help