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,360 points
61 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
• 9,940 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,360 points
103 views
0 votes
2 answers

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

You are getting this error since the ...READ MORE

answered Aug 16, 2019 in Data Analytics by anonymous
• 32,440 points
3,551 views
+2 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 in Data Analytics by ramthotahappy
• 140 points
179 views
+9 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 Anmol
• 3,680 points
124 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,800 points
51 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
• 9,940 points
74 views
0 votes
1 answer