Search code examples
rdataframescalingr-caret

Feature scaling in R


I want to scaling my feature using the caret package my data set is train[,1:10]: independent variable train[11]: is my dependent variable

I used the code below to scale my 10 independent variables:

library(caret)
# calculate the pre-process parameters from the dataset
preprocessParams <- preProcess(train[,1:10], method = "range")
# transform the dataset using the parameters
train_Scaled <-predict(pp, train[,1:10])
# summarize the transformed dataset
summary(train_Scaled)

Therefore my train_Scaled data frame will have scaled 10 independent variable i want but don't have the dependent variable any more. how can i attach my dependent variable to my new train_Scaled data frame? Thank you!


Solution

  • cbind(train_Scaled, train[,11])