[R] cbind and automatic type conversion

Uwe Ligges ligges at statistik.tu-dortmund.de
Sun May 2 16:52:51 CEST 2010



On 01.05.2010 21:09, Giovanni Azua wrote:
> Hello,
>
> I have three method types and 100 generalization errors for each, all in the range [0.65,0.81]. I would like to make a stacked histogram plot using ggplot2 with this data ...
>
> Therefore I need a data frame of the form e.g.
>
> Method                   GE
> ----------                   ------
> "Classic"                0.76
> "Classic"                0.79
> "Own Bootstrap"   0.81
> "Own Bootstrap"   0.79
> "R Bootstrap"        0.71
> "R Bootstrap"        0.75
>
> So I combine the data in the following way:
>
> normalerrors<- rbind(cbind(rep("Classic",S),classicge[,1]),
>      cbind(rep("Own Bootstrap",S),ownge[,1]),cbind(rep("R Bootstrap",S),rbootge[,1]))
> normalerrors<- data.frame(method=factor(normalerrors[,1]),ge=normalerrors[,2])
>
> But doing it in this way my GE coefficients get automatically converted to string type ... how can I avoid this conversion when doing the cbind?

Not at all, since cbind() constructs a matrix which is of exactly one 
type. You probably want to construct the data.frame directly as in


labels <- c("Classic", "Own Bootstrap", "R Bootstrap")
normalerrors <- data.frame(
     method = gl(length(labels), S, labels = labels),
     ge = c(classicge[,1], ownge[,1], rbootge[,1]))

Best,
Uwe Ligges

>
> TIA,
> Best regards,
> Giovanni
>
>
> 	[[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.



More information about the R-help mailing list