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
2,326 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,010 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
459 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,360 points
1,920 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,240 points
1,134 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 19, 2018 in Data Analytics by DataKing99
• 8,240 points
1,470 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
955 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
613 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,011 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,010 points
851 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,010 points
938 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,010 points
3,987 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP