[R] Training set in Self organizing Map

Ulrik Stervbo ulrik.stervbo at gmail.com
Wed Jun 1 17:01:44 CEST 2016


Hi Elahe,

if you look at your subdf, you will see that the column Country - which is
not numeric - is still present. You might have other non-number columns,
but this I cannot tell.

scale expects a numeric matrix. You give it a data.frame which is silently
cast to a matrix. A matrix can only have one type - unlike the data.frame -
so the presence of the non-numeric columns results in a matrix of type
character. Calculating means of characters is not possible, hence the error.

You need your data.frame to consist only of numeric types - then scale will
proceed without complaints.

Best wishes,
Ulrik



On Wed, 1 Jun 2016 at 16:41 ch.elahe via R-help <r-help at r-project.org>
wrote:

> Hi all,
> I want to use Self Organizing Map in R for my data. I want my training set
> to be the following subset of my data:
>
>
>     subdf=subset(df,Country%in%c("US","FR"))
> next I should change this subset to a matrix but I get the following error:
>
>     data_train_matrix=as.matrix(scale(subdf))
>     error in colMeans(x,na.rm=TRUE):'x' must be numeric
>
> Can anyone help me to solve that?
> Thanks for any help
> Elahe
>
> ______________________________________________
> R-help at r-project.org 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]]



More information about the R-help mailing list