Dear Sir, I am facing an error when I am trying to use svm and found similar kind of problem faced by other. But I unable to solve the problem. The problem is given below.> rm(list=ls(all=TRUE)) > CombinedGeneList <- read.xlsx(file.choose(), sheet = 1, colNames TRUE,rowNames = TRUE) > NoemalisedData <- read.xlsx(file.choose(), sheet=1,colNames TRUE,rowNames = TRUE) > status<-NoemalisedData[1, ] > FilterData <-NoemalisedData[rownames(CombinedGeneList), ] > TFilterData <- t(FilterData) > Tstatus <- t(status) > x<-TFilterData > y<-Tstatus > model <- svm( x, y)Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric>Please solve the problem. I have tried it in many ways. Waiting for your reply. Thank you With regards Pijush [[alternative HTML version deleted]]
Hi Pijush, Without access to the data, we can only guess. However, in such cases the problem is often a factor variable where you expect a numeric one. Try this: is.factor(x) and if the answer is TRUE, you have found your problem. Jim On Wed, Jun 3, 2015 at 4:13 PM, Pijush Das <topijush at gmail.com> wrote:> Dear Sir, > > I am facing an error when I am trying to use svm and found similar kind of > problem faced by other. But I unable to solve the problem. The problem is > given below. > >> rm(list=ls(all=TRUE)) >> CombinedGeneList <- read.xlsx(file.choose(), sheet = 1, colNames > TRUE,rowNames = TRUE) >> NoemalisedData <- read.xlsx(file.choose(), sheet=1,colNames > TRUE,rowNames = TRUE) >> status<-NoemalisedData[1, ] >> FilterData <-NoemalisedData[rownames(CombinedGeneList), ] >> TFilterData <- t(FilterData) >> Tstatus <- t(status) >> x<-TFilterData >> y<-Tstatus >> model <- svm( x, y) > Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric >> > > > > Please solve the problem. I have tried it in many ways. > Waiting for your reply. > Thank you > > > > With regards > Pijush > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.
Hi Pijush, First, please keep the messages on the help list. As far as I can determine, the "x" in your code above is a matrix of character strings. When you transpose (t) the initial data frame, all of the numbers are coerced to character mode as the columns must all be of the same mode. The first column, being of character mode, causes all of the other columns to be coerced to character. What you may want to do is something like this: FilterData<-NoemalisedData[,-1] TFilterData <- t(FilterData) x<-TFilterData is.numeric(x) [1] TRUE This removes the first column of NoemalisedData so that the remaining columns are numeric, and remain so after the transpose. If you are using "svm" from the e1071 package, this might solve your problem. Jim On Wed, Jun 3, 2015 at 5:09 PM, Pijush Das <topijush at gmail.com> wrote:> Hi Jim, > > > First of all thank you for your immediate reply. > > please find the attachment. I am sending two excel file where > the the first file (Data) contained the raw data and the list is also > given in another file and the code has been send before. The variable named > "NoemalisedData" is used to get the value from Data.excel file. > > > > Please try and send me the code. I am also trying it in my way. > > Thank you. > > > > With Regards > Pijush > > > On Wed, Jun 3, 2015 at 12:04 PM, Jim Lemon <drjimlemon at gmail.com> wrote: >> >> Hi Pijush, >> Without access to the data, we can only guess. However, in such cases >> the problem is often a factor variable where you expect a numeric one. >> Try this: >> >> is.factor(x) >> >> and if the answer is TRUE, you have found your problem. >> >> Jim >> >> >> On Wed, Jun 3, 2015 at 4:13 PM, Pijush Das <topijush at gmail.com> wrote: >> > Dear Sir, >> > >> > I am facing an error when I am trying to use svm and found similar kind >> > of >> > problem faced by other. But I unable to solve the problem. The problem >> > is >> > given below. >> > >> >> rm(list=ls(all=TRUE)) >> >> CombinedGeneList <- read.xlsx(file.choose(), sheet = 1, colNames >> > TRUE,rowNames = TRUE) >> >> NoemalisedData <- read.xlsx(file.choose(), sheet=1,colNames >> > TRUE,rowNames = TRUE) >> >> status<-NoemalisedData[1, ] >> >> FilterData <-NoemalisedData[rownames(CombinedGeneList), ] >> >> TFilterData <- t(FilterData) >> >> Tstatus <- t(status) >> >> x<-TFilterData >> >> y<-Tstatus >> >> model <- svm( x, y) >> > Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric >> >> >> > >> > >> > >> > Please solve the problem. I have tried it in many ways. >> > Waiting for your reply. >> > Thank you >> > >> > >> > >> > With regards >> > Pijush >> > >> > [[alternative HTML version deleted]] >> > >> > ______________________________________________ >> > 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. > >
Hi Pijush, As before, please keep the messages on the mailing list. In your example above you have not defined "y", so the function is probably complaining about being passed a NULL for the dependent variable. I forgot to add in my previous message that I imported your data by exporting it from XLSX format to CSV format and then removing the second line, which seems to be a subsidiary header. If not removed, that second line will also cause the data to be imported to R as character mode variables because R reads the first line as a header (variable names) and then tries to work out from the subsequent lines the modes of the data. As the first line of "data" is of character mode if the second line of the spreadsheet is not removed, everything else will be demoted to that mode. Jim On Wed, Jun 3, 2015 at 11:51 PM, Pijush Das <topijush at gmail.com> wrote:> Dear Jim, > > To overcome the "'x' must be numeric" error I found a easy solution, given > below. > > > p<-matrix( nrow=10, ncol=1630) > > for(i in 1:1630){ > for(j in 1:10){ > a<-FilterData[i,j] > p[j,i]<- as.numeric(a) > > } > } > > > But I have faced another problem. which is : > >> model <- svm( p, y) > Error in svm.default(p, y) : > Need numeric dependent variable for regression. > > > Can you please try to solve this short of problem. > I have also send an e-mail to the Maintainer of > ?e1071? Package. Lets see what will they answer. > > > > > Thanking you > > > > With regards > Pijush. > > > On Wed, Jun 3, 2015 at 4:09 PM, Pijush Das <topijush at gmail.com> wrote: >> >> Dear Jim, >> >> >> Thank you very much for your kind help. >> But the problem is still there. >> >> >> >> with regards >> Pijush >>