[R] kill colnames Matrix

PIKAL Petr petr.pikal at precheza.cz
Mon Oct 7 10:44:59 CEST 2013


Hi

First of all do not mix data frame and matrix, they have quite different properties.

By transposing data frame you got character matrix and you cannot do barplot with characters.
So you shall transpose only column PT_SATZ and add names from MONTHS but why not to use your data frame directly?

dat<-data.frame(x=letters[1:5], y=1:5)
barplot(dat[,2], names.arg=dat[,1])

You could arrive to this answer quicker if you bother to look into documentation to barplot so as did I.

Regards
Petr

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Mat
> Sent: Monday, October 07, 2013 9:58 AM
> To: r-help at r-project.org
> Subject: [R] kill colnames Matrix
> 
> Hello together,
> 
> i have a little problem, maybe you can help me.
> I have a matrix like this one:
> 
>                    [,1]          [,2]              [,3]           [,4]
> [,5]
> MONTH         "2012-10"    "2012-11"    "2012-12"    "2013-01"
> "2013-02"
> PT_SATZ "     0.00000" " 500.53621" "  65.71684" "1080.58285"
> "1013.72028"
> 
> For a bar plot i need this matrix in the following formatting:
> 
> "2012-10"    "2012-11"    "2012-12"    "2013-01"    "2013-02"
> 0.00000"    " 500.53621"  "  65.71684" "1080.58285" "1013.72028"
> 
> the data comes from a data.frame like this one:
> 
>      MONTH    PT_SATZ
> 1  2012-10    0.00000
> 2  2012-11  500.53621
> 3  2012-12   65.71684
> 4  2013-01 1080.58285
> 5  2013-02 1013.72028
> 6  2013-03  939.63030
> 7  2013-04  977.17073
> 8  2013-05    0.00000
> 9  2013-06    0.00000
> 10 2013-07 1047.56938
> 11 2013-08  225.44031
> 12 2013-09  667.91489
> 13 2013-10    0.00000
> 
> i converted this data.frame with plotbase<-t(plotbase).
> 
> Maybe you can help me.
> 
> Thanks Mat
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/kill-
> colnames-Matrix-tp4677726.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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.



More information about the R-help mailing list