1

While programming in R, I'm continuosly facing the following error::

Error in data.validity(data, "data") : Bad usage: input 'data' is not double type.

Can anyone please explain why this error is happening, i.e. the reasons in the dataset which cause the error to arise?

Here is the code I'm running. The packages I have loaded are cluster, psych and clv.

data1 <- read.table(file='dataset.csv', sep=',', header=T, row.names=1)
data1.p <- as.matrix(data1)
hello.data <- data1.p[,1:15]
agnes.mod <- agnes(hello.data)
v.pred <- as.integer(cutree(agnes.mod,3)) # "cut" the tree
scatt <- clv.Scatt(hello.data, v.pred)

Error in data.validity(data, "data") :
 Bad usage: input 'data' is not double type.
joran
  • 169,992
  • 32
  • 429
  • 468
  • 1
    No one is going to be able to help with out more information. What code are you running that generates this error? What packages are you loading? – joran Jan 06 '12 at 16:39
  • 3
    Please provide us with a reproducible example. the function data.validity is unknown to my R engine for example... See also: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Joris Meys Jan 06 '12 at 16:40

1 Answers1

3

The key part of data.validity() raising the error is:

data = as.matrix(data)
if( !is.double(data) )
    stop(paste("Bad usage: input '", name, "' is not double type.", sep=""))

data is converted to a matrix and then checked if it is a numeric matrix via is.double(). If it isn't numeric the clause is true and the error raised. So why isn't your data (hello.data) numeric when converted to a matrix? Either you have character variables in your data or there are factors. Do you have factors? Try

str(hello.data)

Are there any non-numeric variables in there? If you have character data then get rid of it. If you have factors, then data.validity() could coerce via data.matrix() but as it doesn't, try

hello.data <- data.matrix(hello.data)

after the line creating hello.data then run the rest of your code.

Whether this makes sense (treating a nominal or ordinal variable as a simple numeric) is unclear as you haven't provided a reproducible example or explained what your data are etc.

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
  • ::Thanks for the reply..but i have a problem..whenver i convert the dataset into a matrix using::> data1 <- read.table(file='data32.csv', sep=',', header=T, row.names=1) > data.p<-as.matrix(data1) whenevr i print out data(data.p)..the function automatically adds column and row names 2 it..how do i avoid that...and is there any other functon which does the same but preserves the matrix as fully numerical? – Arnab Kumar Jan 06 '12 at 18:54
  • Why are you doing `data(data.p)` You are specifying that the data have row and column names. R will take the first row and column (because that's what `header = TRUE` and `row.names = 1` means!) as the rownames and colnames attributes (or dimnames) of the resulting object. Just because R prints them doesn't mean they are part of the data. Please edit your question to show the output of `str(hello.data)` as I asked. Second, I did mention you could use `data.matrix()` instead of `as.matrix()`. Note the two comments to your question for pointers on how to improve you Q. – Gavin Simpson Jan 06 '12 at 19:05
  • @ArnabKumar if the answer solved your problem, consider accepting it so that others with the same or similar problem can see if an answer was helpful or not. See the *How do I ask Questions here* section of the FAQ: http://stackoverflow.com/faq#howtoask – Gavin Simpson Jan 09 '12 at 10:50