I have a data frame that contains both numeric and non-numeric columns, say
df <- data.frame(v1=1:20,v2=1:20,v3=1:20,v4=letters[1:20],v5=letters[1:20])
To select only non-numeric columns, I would use
fixCol <- !sapply(df,is.numeric)
But now I also want to include a specific numeric column, say v2. My data frame is very large and the order of the columns is changing, so I cannot index it with a number, I really want to use the name "v2". I tried
fixCol$v2 = TRUE
but this gives me a warning In fixCol$FR = TRUE : Coercing LHS to a list , which makes it impossible for a subset of my original data frame to get only fixCol
df[,fixCol]
gives: Error in .subset(x, j) : invalid subscript type 'list'
In the end, my goal is to scale all the numeric columns of my data frame except this specified column using something like this
scaleCol = !fixCol df_scaled = cbind(df[,fixCol], sapply(df[,scaleCol],scale))
How can i do this?
Ciska source share