PAM Clustering

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

PAM Clustering

Sema Atasever
Dear Authorized Sir / Madam,

I have an R script file in which it includes PAM Clustering codes:

*when i ran R script i am getting this error:*
*Error in pam(d, 10) : x is not a numeric dataframe or matrix.*
*Execution halted*

How can i fix this error?

Thanks in advance.

 data.csv
<https://drive.google.com/file/d/0B4rY6f4kvHeCcVpLRTQ5VDhDNUk/view?usp=drive_web>


*pam.R*
data <- read.csv2("data.csv")
attach(data)
d=as.matrix(data)
library(cluster)
cluster.pam = pam(d,10)
table(cluster.pam$clustering)

filenameclu = paste("clusters", ".txt")
write.table(cluster.pam$clustering, file=filenameclu,sep=",")

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PAM Clustering

Ulrik Stervbo-2
Hi Sema,

read.csv2 use ',' as the decimal separator. Since '.' is used in your file,
everything becomes a character which in turn makes pam complain that what
you pass to the function isn't numeric.

Use read.csv2("data.csv", dec = ".") and it should work.

You can also use class(d) to check the class of the matrix before you pass
it to pam().

See ?read.table for more options.

There is a base function called 'data', so naming a variable data is a poor
choice.

HTH
Ulrik

On Mon, 10 Jul 2017 at 17:25 Sema Atasever <[hidden email]> wrote:

> Dear Authorized Sir / Madam,
>
> I have an R script file in which it includes PAM Clustering codes:
>
> *when i ran R script i am getting this error:*
> *Error in pam(d, 10) : x is not a numeric dataframe or matrix.*
> *Execution halted*
>
> How can i fix this error?
>
> Thanks in advance.
> ​
>  data.csv
> <
> https://drive.google.com/file/d/0B4rY6f4kvHeCcVpLRTQ5VDhDNUk/view?usp=drive_web
> >
> ​
>
> *pam.R*
> data <- read.csv2("data.csv")
> attach(data)
> d=as.matrix(data)
> library(cluster)
> cluster.pam = pam(d,10)
> table(cluster.pam$clustering)
>
> filenameclu = paste("clusters", ".txt")
> write.table(cluster.pam$clustering, file=filenameclu,sep=",")
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Loading...