Data slicing using R programming

0 votes

I have the following dataset:

ID   age   sugarlevel

123  12      8

456  13      10

789  25      5

...  

I'm trying to use R to split the data depending on the sugar level (>=7, <7)

This should give me 2 groups:

group 1:

ID  age  sugarlevel

123  12     8

456  13      10



group 2:

ID  age  sugarlevel

789  25      5

Jan 9 in Data Analytics by Sophie may
• 9,530 points
47 views

1 answer to this question.

0 votes

You can perform data slicing by splitting the dataset by using a grouping variable df1$sugarlevel >=7 

 First <- setNames(split(df1, df1$sugarlevel >=7), paste0('group',1:2))
 First
 #$group1
 # ID age sugarlevel
 #3 789  25          5

 #$group2
 #   ID age sugarlevel
 #1 123  15          8
 #2 456  13         10

Hope this helped!

answered Jan 9 by Tyrion anex
• 8,270 points
Nice question. This code will split the dataset and add them in the same variable.

Access the variable using first$group1.

Thanks, it helped me.

Related Questions In Data Analytics

0 votes
1 answer

Data segmentation using R programming

I tried solving your problem, try the ...READ MORE

answered Jan 4 in Data Analytics by Sophie may
• 9,530 points
40 views
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,140 points
68 views
0 votes
1 answer

How to forecast season and trend of data using STL and ARIMA in R?

You can use the forecast.stl function for the ...READ MORE

answered May 18, 2018 in Data Analytics by DataKing99
• 8,130 points
509 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
28 views
0 votes
1 answer
+4 votes
2 answers
0 votes
2 answers
0 votes
1 answer

Concurrent Programming Using R

Concurrent programming has been supported by various ...READ MORE

answered Jan 9 in Data Analytics by Tyrion anex
• 8,270 points
55 views