Create train and test data from dataset in R

0 votes

How to create train and test data from a dataset using R?

Sep 30, 2019 in Data Analytics by ch
• 3,450 points
3,278 views

1 answer to this question.

0 votes
Hi,

Use sample or sample.split function to create train and test data.

For example:

split = sample.split(db$Class.variable,0.6)
train = subset(db,split==T)
test = subset(db,split==F)

split_data=sample(1:nrow(db),0.6*nrow(db))
train_data = db[split_data,]
test_data = db[-split_data,]
answered Oct 14, 2019 by anonymous
• 33,030 points

Related Questions In Data Analytics

0 votes
2 answers

"Train" and "Test" sets in Data Science

Normally to perform supervised learning you need ...READ MORE

answered Aug 3, 2018 in Data Analytics by Abhi
• 3,720 points
1,324 views
+3 votes
1 answer

R plot for train and test data on same graph

Hi, You can use the subplot function. It ...READ MORE

answered Jul 27, 2020 in Data Analytics by MD
• 95,460 points
3,269 views
0 votes
0 answers

Create data frame from function in R

One function that I designed can produce ...READ MORE

Jul 9, 2022 in Data Analytics by avinash
• 1,840 points
781 views
0 votes
1 answer

How to filter a data frame with dplyr and tidy evaluation in R?

Requires the use of map_df to run each model, ...READ MORE

answered May 17, 2018 in Data Analytics by DataKing99
• 8,250 points
1,899 views
0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,920 views
0 votes
1 answer

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,339 views
0 votes
1 answer

How to spilt a column of a data frame into multiple columns

it is easily achievable by using "stringr" ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,774 views
+1 vote
2 answers

How to sort a data frame by columns in R?

You can use dplyr function arrange() like ...READ MORE

answered Aug 21, 2019 in Data Analytics by anonymous
• 33,030 points
1,812 views
0 votes
1 answer

Create a tree model in R from data.frame?

See the below example to understand how ...READ MORE

answered Aug 30, 2019 in Data Analytics by anonymous
• 33,030 points
1,743 views
0 votes
2 answers

Top N and Last N records in R Data Frame

Hi, top_n( ) and top_frac( ) also is ...READ MORE

answered Sep 3, 2019 in Data Analytics by anonymous
• 33,030 points
5,116 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