Reputation: 713
I'm using R and the cars data frame.
I want to do a test :
1/ Scale the "cars" data in cars.scale
2/ Unscale cars.scale in order to check if I recover "cars" data
I did this but it doesn't work
data(cars)
library(DMwR)
cars.scale<- scale(cars)
head(cars)
head(cars.scale)
original_data <- unscale(cars.scale, cars)
I obtain this error message :"Error in -centers : invalid argument to unary operator"
Could you please help me to understand what's wrong ?
Upvotes: 1
Views: 2648
Reputation: 23574
If you read the CRAN manual, you have the answer there. The first argument in the function is "a numeric matrix with the values to un-scale", which is cars.scale
. The second argument is "an object to which the function scale()
was applied", which is also cars.scale
.
original_data <- unscale(cars.scale, cars.scale)
# speed dist
# [1,] 4 2
# [2,] 4 10
# [3,] 7 4
# [4,] 7 22
# [5,] 8 16
From the CRAN manual
unscale(vals, norm.data, col.ids)
Arguments
vals A numeric matrix with the values to un-scale
norm.data A numeric and scaled matrix. This should be an object to which the function scale() was applied.
col.ids The columns of the vals matrix that are to be un-scaled (defaults to all of them).
Upvotes: 1