JayR
JayR

Reputation: 1

length of 'center' must equal the number of columns of 'x'

I'm trying to scale a matrix in R. I have:

maxs<- apply(rawsingle,2,max)
mins<- apply(rawsingle,2,min)

and then

scaledss<- scale(rawsingle,center=mins,scale = (maxs-mins))

I get the error:

'Error in scale.default(rawsingle, center = mins, scale = (maxs - mins)) :
length of 'center' must equal the number of columns of 'x''

Immediately following the error, I typed:

 length(mins)==ncol(rawsingle)

and it returned TRUE, so I have no idea whats going on.

Has anyone had a similar issue before?

Upvotes: 0

Views: 1936

Answers (2)

JayR
JayR

Reputation: 1

The problem was that some elements in 'rawsingle' were character strings due to an error in loading it.

Upvotes: 0

statistical_model
statistical_model

Reputation: 21

All the variables needs to be of type numeric:

dades[2:13] <- lapply(dades[2:13], as.numeric)

Upvotes: 0

Related Questions