-
Notifications
You must be signed in to change notification settings - Fork 18
/
s3.RemNearZeroVar.R
29 lines (24 loc) · 1021 Bytes
/
s3.RemNearZeroVar.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# ==========================================
# Removal of near zero variance columns
# ==========================================
# contact: Cristian R Munteanu | BiGCaT - UM | muntisa@gmail.com
#
# inputs:
# - ds = dataset frame
# - fDet = flag for detais (TRUE/FALSE)
# - outFileName = new file name (it could include the path)
# output = ds.Rem0NearVar (ds without columns with near zero variance)
# if datails = TRUE, output the new ds as a file
# ------------------------------------------
RemNear0VarCols <- function(ds,fDet=FALSE,outFile="") {
# default parameters are no details, without a file name
ds.Rem0NearVar <- ds # default output without any modification
library(caret)
ds.var <- nearZeroVar(ds) # get the near zero columns
ds.Rem0NearVar <- ds[,-(ds.var)] # get only the columns without this problem
if (fDet == TRUE) {
# write the corrected ds file
write.csv(ds.Rem0NearVar, outFile,row.names=F, quote=F)
}
return(as.data.frame(ds.Rem0NearVar)) # return the new ds
}