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
• 10,100 points
175 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,560 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
• 10,100 points
80 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 1 in Data Analytics by ramthotahappy
• 160 points
271 views
0 votes
1 answer
+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 8, 2018 in Data Analytics by Abhi
• 3,720 points
223 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
74 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,490 points
17,663 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,560 points
175 views