Hi. First of all, excuse me if I do any mistakes, but English is not a language I use very often.
I have a data frame with numbers. A small part of the data frame is this: nominal ordinal 2 2 2 1 2 1 2 2 So, I want to use the gower distance function on these numbers. Here ( http://rgm2.lab.nig.ac.jp/RGM2/R_man-2.9.0/library/StatMatch/man/gower.dist.html) says that in order to use gower.dist, all nominal variables must be of class "factor" and all ordinal variables of class "ordered". By default, all the columns are of class "integer" and mode "numeric". In order to change the class of the columns, i use these commands: > DF=read.table("clipboard",header=TRUE,sep="\t") *# I select all the cells and I copy them to the clipboard. Then R, with this command, reads the data from there.* > MyHeader=names(DF) *# I save the headers of the data frame to a temp matrix* > for (i in 1:length(DF)) {if (MyHeader[[i]]=="nominal") DF[[i]]=as.factor(DF[[i]])} > for (i in 1:length(DF)) {if (MyHeader[[i]]=="ordinal") DF[[i]]=as.ordered(DF[[i]])} * * The first for/if loop changes the class from integer to factor, which is what I want, but the second changes the class of ordinal variables to: "ordered" "factor". I need to change all the columns with the header "ordinal" to "ordered", as the gower.dist function says. Thanks in advance, B.T. [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list 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.