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 in Data Analytics by ch
• 3,290 points
24 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 by anonymous
• 31,840 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 Anmol
• 3,620 points
58 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,130 points
132 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,130 points
584 views
0 votes
1 answer

Reshape data from long to wide format in R

Use reshape function: reshape(dat1, idvar = "name", timevar = ...READ MORE

answered Jun 13, 2018 in Data Analytics by CodingByHeart77
• 3,690 points
119 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
154 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
97 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
103 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 in Data Analytics by anonymous
• 31,840 points
146 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 in Data Analytics by anonymous
• 31,840 points
50 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 in Data Analytics by anonymous
• 31,840 points
43 views