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,610 points
740 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,700 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 5, 2019 in Data Analytics by Sophie may
• 10,610 points
461 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 2, 2020 in Data Analytics by ramthotahappy
• 160 points
764 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 9, 2018 in Data Analytics by Abhi
• 3,720 points
1,119 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,840 points
469 views
0 votes
1 answer
+1 vote
3 answers

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

Try this: df$symbol <- as.character(df$symbol) df$symbol[df$sym ...READ MORE

answered Jan 11, 2019 in Data Analytics by Tyrion anex
• 8,700 points
35,166 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,700 points
678 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP