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, 2019 in Data Analytics by Tyrion anex
• 8,660 points
126 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, 2019 by Sophie may
• 10,550 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, 2019 in Data Analytics by Tyrion anex
• 8,660 points
256 views
+1 vote
3 answers

How to change the value of a variable using R programming in a data frame?

Try this: df$symbol <- as.character(df$symbol) df$symbol[df$sym ...READ MORE

answered Jan 11, 2019 in Data Analytics by Tyrion anex
• 8,660 points
26,797 views
+4 votes
0 answers

I was unable to cluster the data points using dbscan in R programming

After using dbscan package I was given with ...READ MORE

Feb 1, 2020 in Data Analytics by ramthotahappy
• 160 points
344 views
+10 votes
3 answers

Which is a better initiative to learn data science: Python or R?

Well it truly depends on your requirement, If ...READ MORE

answered Aug 8, 2018 in Data Analytics by Abhi
• 3,720 points
352 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,840 points
124 views
0 votes
1 answer
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, 2019 in Data Analytics by Sophie may
• 10,550 points
1,183 views
+1 vote
1 answer