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,380 points
687 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 13, 2019 by anonymous
• 32,460 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 2, 2018 in Data Analytics by Abhi
• 3,680 points
147 views
0 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 in Data Analytics by MD
• 42,780 points
36 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 16, 2018 in Data Analytics by DataKing99
• 8,150 points
418 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 18, 2018 in Data Analytics by DataKing99
• 8,150 points
928 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
383 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
231 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
343 views
0 votes
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
• 32,460 points
358 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
• 32,460 points
327 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
• 32,460 points
1,398 views