Hi, I am a brand new user of R and I have a really stupid problem: I am having troubles applying fft on 2D matrices. I import a data file of 256*256 elements with read.table (it is actually a grey scale image, the corresponding data file being generated with Matlab), and I find that the fft can be applied on one single column of data, but not on one row. (Error message: Error in fft(z, inverse) : non-numeric argument ) Is it the format of the matrix which causes that trouble? (although I checked with the editor that the matrix was well imported) Besides this, it is not possible to plot one single row of data (strange plot with the names of variables appearing). Thanks in advance for your help, Anne Gosset [[alternative HTML version deleted]]
Anne Gosset wrote:> Hi, > > I am a brand new user of R and I have a really stupid problem: I am having troubles applying fft on 2D matrices. > I import a data file of 256*256 elements with read.table (it is actually a grey scale image, the corresponding data file being generated with Matlab), and I find that the fft can be applied on one single column of data, but not on one row. > (Error message: > Error in fft(z, inverse) : non-numeric argument > )Be careful: read.table() creates a data.frame, but not a matrix.> Is it the format of the matrix which causes that trouble?Well, the trouble is that it is a data.frame. Try as.matrix(X), if the contents was numeric data. > (although I checked with the editor that the matrix was well imported)> Besides this, it is not possible to plot one single row of data (strange plot with the names of variables appearing).Again, you got a data.frame with 1 row, but 256 variables. Hence the plot is a scatterplot matrix, with the one observation plotted. Uwe Ligges> Thanks in advance for your help, > > Anne Gosset > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
On Thu, 1 Apr 2004, Anne Gosset wrote:> Hi, > > I am a brand new user of R and I have a really stupid problem: I am > having troubles applying fft on 2D matrices. I import a data file of > 256*256 elements with read.table (it is actually a grey scale image, the > corresponding data file being generated with Matlab), and I find that > the fft can be applied on one single column of data, but not on one row. > (Error message: Error in fft(z, inverse) : non-numeric argument ) > > Is it the format of the matrix which causes that trouble? (although I > checked with the editor that the matrix was well imported) Besides this, > it is not possible to plot one single row of data (strange plot with the > names of variables appearing). >You probably have a data.frame rather than a matrix, as that is what read.table() produces. The difference is not obvious to the untrained eye, but a data.frame is a list of columns of potentially different types, so a single column reduces to a vector but a single row does not. Use as.matrix() on your data frame to convert it to a matrix. -thomas