I have a dataset I've imported from excel using readxl
called GSMA. Checking the class of the object returns:
class(GSMA)
[1] "tbl_df" "tbl" "data.frame"
I want to standardise columns 2 through 4 using base scale. I try running:
GSMA[2:4] <- scale(GSMA[2:4])
This results in an incorrectly scaled dataframe, with each row having the same value for all columns.
A potential clue to the problem: When I attempt to sort the incorrectly scaled dataframe, this error is returned:
Error in xj[i, , drop = FALSE] : subscript out of bounds
When I re-import the same dataset, and then run:
GSMA <- as.data.frame(GSMA)
GSMA[2:4] <- scale(GSMA[2:4])
The dataframe columns scale correctly.
What is going on? Why is base scale not working in the first instance?
dput(head(GSMA))
structure(list(Country = c("GBR", "CHE", "DEU", "ROU", "LUX",
"KAZ"), entry = c(98.4974384307861, 95.6549962361654, 91.4044539133708,
90.8518393834432, 90.4088099797567, 88.0471547444662), medium = c(86.0081672668457,
93.0372142791748, 91.2993144989014, 100, 96.7348480224609, 100
), high = c(74.6774760159579, 84.1793060302734, 79.542350769043,
99.6931856328791, 97.031680020419, 92.5396745855158)), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))