Did some search but couldn't find useful result. I am trying to read a n*m dimension data with read.table, what i need is a numeric array, is there any efficient way to allow me get this array directly instead of a list? I tried to use as.array() to change the mode, but seems it doesn't work and i got this error message: "Error in "dimnames<-.data.frame"(`*tmp*`, value = list(function (M) : invalid dimnames given for data frame " what's wrong with the dimension names , should i delete them? how can i do that? Thanks a lot for any help. tong wang
maybe you can use the array function,like>array(CO2,dim(CO2),list(rownames(CO2),colnames(CO2)))and matrix is just a specif type of array,so maybe you can use as.matrix>as.matrix(CO2)the above tow,the CO2 is a data.frame which can use read.table to read in. the third way is:use the scan the read the data and use array to change the data to array. On Tue, 28 Jun 2005 01:05:23 -0700 tong wang <wangtong at usc.edu> wrote:> Did some search but couldn't find useful result. > > I am trying to read a n*m dimension data with read.table, what i need is a numeric array, > is there any efficient way to allow me get this array directly instead of a list? > I tried to use as.array() to change the mode, but seems it doesn't work and i got this error message: > > "Error in "dimnames<-.data.frame"(`*tmp*`, value = list(function (M) : > invalid dimnames given for data frame " > > what's wrong with the dimension names , should i delete them? how can i do that? > > Thanks a lot for any help. > > tong wang > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html-- Department of Sociology Fudan University,Shanghai Blog:http://sociology.yculblog.com
Please consult the `R Data Import/Export Manual'. You could be using scan(), as in matrix(scan("some_file", 0), nrow=n, byrow=TRUE) On Tue, 28 Jun 2005, tong wang wrote:> Did some search but couldn't find useful result. > > I am trying to read a n*m dimension data with read.table, what i need is > a numeric array, is there any efficient way to allow me get this array > directly instead of a list? I tried to use as.array() to change the > mode, but seems it doesn't work and i got this error message: > > "Error in "dimnames<-.data.frame"(`*tmp*`, value = list(function (M) : > invalid dimnames given for data frame " > > what's wrong with the dimension names , should i delete them? how can i do that?I think you wanted as.matrix here, not as.array: probably the call to the latter was incorrect, but we were not shown it. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595