Strange things are going on in R, if you reshape a matrix in R:> g=gretldata[1:2,] > gEmpfang Versand Transit Inland Ausland SumS 1 787844.0 1307176.6 223395.4 1474726 16199.1 3809341 2 421473.1 306445.4 448801.2 1779402 14445.6 2970567> dim(g)[1] 2 6> as.vector(g)Empfang Versand Transit Inland Ausland SumS 1 787844.0 1307176.6 223395.4 1474726 16199.1 3809341 2 421473.1 306445.4 448801.2 1779402 14445.6 2970567> gg=matrix(as.vector(g),nrow=1,byrow=TRUE) > gg[,1] [,2] [,3] [,4] [,5] [,6] [1,] Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2>Help please,the docu on thids is lousy!!!. Wolfgang [[alternative HTML version deleted]]
Wolfgang Polasek wrote:> Strange things are going on in R, if you reshape a matrix in R: > >> g=gretldata[1:2,] >> g >> > Empfang Versand Transit Inland Ausland SumS > 1 787844.0 1307176.6 223395.4 1474726 16199.1 3809341 > 2 421473.1 306445.4 448801.2 1779402 14445.6 2970567 > >> dim(g) >> > [1] 2 6 > >> as.vector(g) >> > Empfang Versand Transit Inland Ausland SumS > 1 787844.0 1307176.6 223395.4 1474726 16199.1 3809341 > 2 421473.1 306445.4 448801.2 1779402 14445.6 2970567 > >> gg=matrix(as.vector(g),nrow=1,byrow=TRUE) >> gg >> > [,1] [,2] [,3] [,4] [,5] [,6] > [1,] Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 > > Help please,the docu on thids is lousy!!!.If you don't like the documentation, then improve it. You don't make friends by insulting people who provide you with something for free. Duncan Murdoch
On Sat, 29 Aug 2009 00:15:45 +0200 Wolfgang Polasek <wolfgang.polasek at gmail.com> wrote: WP> > g=gretldata[1:2,] WP> > g WP> Empfang Versand Transit Inland Ausland SumS WP> 1 787844.0 1307176.6 223395.4 1474726 16199.1 3809341 WP> 2 421473.1 306445.4 448801.2 1779402 14445.6 2970567 WP> > dim(g) WP> [1] 2 6 WP> > as.vector(g) WP> Empfang Versand Transit Inland Ausland SumS WP> 1 787844.0 1307176.6 223395.4 1474726 16199.1 3809341 WP> 2 421473.1 306445.4 448801.2 1779402 14445.6 2970567 WP> > gg=matrix(as.vector(g),nrow=1,byrow=TRUE) WP> > gg WP> [,1] [,2] [,3] [,4] [,5] [,6] WP> [1,] Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 WP> > WP> Help please,the docu on thids is lousy!!!. Depending on what you want which is not really clear again, you can use ?reshape or maybe also ?stack to reshape a data-frame which gretldata supposedly is. Note that with your as.vector(g) you dont create a vector as: dat1<-data.frame(x=1:3, y=5:7) v1<-as.vector(dat1) str(v1) resp. is.vector(v1) clearly shows. So you were also not "debugging" your problem. And you clearly did not have a look at the "lousy" documentation as this is shown in the example in ?as.vector, so don't blame others! Cheers Stefan
g does not appear to be a matrix, as described. Its more likely a data frame. If that is the case then as.matrix(g) will create a matrix from it. Also depending on what you want to do ?unlist, ?t or ?c may be of help. Also try str(g) and dput(g) to see internals of object as they seem not to be what you believe them to be. On Fri, Aug 28, 2009 at 6:15 PM, Wolfgang Polasek<wolfgang.polasek at gmail.com> wrote:> Strange things are going on in R, if you reshape a matrix in R: >> g=gretldata[1:2,] >> g > ? Empfang ? Versand ?Transit ?Inland Ausland ? ?SumS > 1 787844.0 1307176.6 223395.4 1474726 16199.1 3809341 > 2 421473.1 ?306445.4 448801.2 1779402 14445.6 2970567 >> dim(g) > [1] 2 6 >> as.vector(g) > ? Empfang ? Versand ?Transit ?Inland Ausland ? ?SumS > 1 787844.0 1307176.6 223395.4 1474726 16199.1 3809341 > 2 421473.1 ?306445.4 448801.2 1779402 14445.6 2970567 >> gg=matrix(as.vector(g),nrow=1,byrow=TRUE) >> gg > ? ? [,1] ? ? ?[,2] ? ? ?[,3] ? ? ?[,4] ? ? ?[,5] ? ? ?[,6] > [1,] Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 >> > ?Help please,the docu on thids is lousy!!!. > Wolfgang > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >
> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Wolfgang Polasek > Sent: Friday, August 28, 2009 3:16 PM > To: r-help at r-project.org > Subject: [R] Numeric, 2 ??? as a result of marix??? > > Strange things are going on in R, if you reshape a matrix in R: > > g=gretldata[1:2,] > > g > Empfang Versand Transit Inland Ausland SumS > 1 787844.0 1307176.6 223395.4 1474726 16199.1 3809341 > 2 421473.1 306445.4 448801.2 1779402 14445.6 2970567 > > dim(g) > [1] 2 6 > > as.vector(g) > Empfang Versand Transit Inland Ausland SumS > 1 787844.0 1307176.6 223395.4 1474726 16199.1 3809341 > 2 421473.1 306445.4 448801.2 1779402 14445.6 2970567 > > gg=matrix(as.vector(g),nrow=1,byrow=TRUE) > > gg > [,1] [,2] [,3] [,4] [,5] [,6] > [1,] Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 > >This last printout is how R prints a matrix whose contents are a "list". Rouughly, if a list element has length 1 its value is printed; otherwise its type and, usually, length are printed. E.g.,> z<-matrix(list(one=1, two=exp(0:1), three=c("i","ii","iii"),four=quote(log(x))), nrow=2)> z[,1] [,2] [1,] 1 Character,3 [2,] Numeric,2 Expression When you see a printout that you cannot interepret, try using the str() function to print the object and you may be able to make sense of it.> str(z)List of 4 $ : num 1 $ : num [1:2] 1 2.72 $ : chr [1:3] "i" "ii" "iii" $ : language log(x) - attr(*, "dim")= int [1:2] 2 2 matrix(data.frame(...)) strips the attributes from the data.frame, making it a list, then attaches dimensions to the list, making an object like 'z' above. as.matrix(data.frame()) makes a matrix that is roughly equivalent to the data.frame input. Bill Dunlap TIBCO Software Inc - Spotfire Division wdunlap tibco.com> Help please,the docu on thids is lousy!!!. > Wolfgang > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >