Data segmentation using R programming

0 votes
This data from accelerometer device has  x, y, z components table. My problem is that on a specific column I want to select data segments using R code.

How can I this be done?

Example: lets say this is the column

2, 1, 3, 0, 0, 0, 1, 4, 5, 1, 0, 0, 0, 2, 3, 0, 4, 5, 0, 0, 0

My result must be a subsets like this

(2, 1, 3), (1, 4, 5, 1), (2, 3, 0, 4, 5)

stored in a variables that I can reuse. I am basically taking data segments between three consecutive zeros. How can I achieve this in R programming?
Jan 4 in Data Analytics by Tyrion anex
• 8,310 points
48 views

1 answer to this question.

0 votes

I tried solving your problem, try the below code:


column <- c(2, 1, 3, 0, 0, 0, 1, 4, 5, 1, 0, 0, 0, 2, 3, 0, 4, 5, 0, 0, 0)

# answer
columnS <- paste(column, collapse="-") 
columnS <- gsub("0-0-0", "=", columnS) 
ds <- strsplit(columnS, "=") 
ds <- strsplit(ds[[1]], "-") 
ds <- lapply(ds, function(x){return(as.numeric(x[x!=""]))})
print(ds)

Hope it helps

answered Jan 4 by Sophie may
• 9,870 points

Related Questions In Data Analytics

0 votes
1 answer

Data slicing using R programming

You can perform data slicing by splitting the ...READ MORE

answered Jan 9 in Data Analytics by Tyrion anex
• 8,310 points
55 views
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer

How to order data frame rows according to vector with specific order using R?

You can try using match: data <- data.frame(alphabets=letters[1:4], ...READ MORE

answered Apr 30, 2018 in Data Analytics by darklord
• 6,190 points
111 views
+1 vote
2 answers
0 votes
1 answer

R programming logic

Use gsub to match the substring that we want ...READ MORE

answered Nov 16, 2018 in Data Analytics by Maverick
• 10,040 points
41 views
0 votes
1 answer
+4 votes
2 answers
0 votes
1 answer

R programming: Naming the output file using a variable

Use the paste command: write.csv(max.hsi, paste0("Index_", i,".csv" ...READ MORE

answered Mar 25 in Data Analytics by Sophie may
• 9,870 points
41 views
0 votes
1 answer