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,940 points
143 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,380 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,940 points
66 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
215 views
0 votes
1 answer
+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 Abhi
• 3,680 points
165 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,820 points
59 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,460 points
9,161 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,380 points
130 views