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 5, 2019 in Data Analytics by Tyrion anex
• 8,700 points
692 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 5, 2019 by Sophie may
• 10,620 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,700 points
1,051 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,700 points
35,865 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 2, 2020 in Data Analytics by ramthotahappy
• 160 points
1,031 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 9, 2018 in Data Analytics by Abhi
• 3,720 points
1,664 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
765 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 26, 2019 in Data Analytics by Sophie may
• 10,620 points
6,570 views
+1 vote
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP