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, 2019 in Data Analytics by Sophie may
• 9,920 points
60 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, 2019 by Tyrion anex
• 8,330 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, 2019 in Data Analytics by Sophie may
• 9,920 points
50 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 Sahiti
• 6,290 points
193 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
666 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
97 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
48 views
0 votes
1 answer
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
1,254 views
0 votes
1 answer

Concurrent Programming Using R

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

answered Jan 9, 2019 in Data Analytics by Tyrion anex
• 8,330 points
79 views