R: [R] Change the result data

Vito Muggeo vito.muggeo at giustizia.it
Fri Feb 27 13:17:13 CET 2004


as.vector is a possible, simple solution
Also use rep() on dimnames(hec.data)[[1]] to get the names vector with
correct length

> a<-matrix(1:15,ncol=5)
> a
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    4    7   10   13
[2,]    2    5    8   11   14
[3,]    3    6    9   12   15
> as.vector(a)
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
> as.vector(t(a))
 [1]  1  4  7 10 13  2  5  8 11 14  3  6  9 12 15


hope this helps,
vito


----- Original Message -----
From: Muhammad Subianto <subianto at cs.uu.nl>
To: <r-help at stat.math.ethz.ch>
Sent: Friday, February 27, 2004 12:28 PM
Subject: [R] Change the result data


> Dear R-helper,
>
> I have a data like:
>
>  > hec.data <-array(c(5,15,20,68,29,54,84,119,14,14,17,26,16,10,94,7),
> +            dim=c(4,4),
> +            dimnames=list(eye=c("Green","Hazel", "Blue", "Brown"),
> +            hair=c("Black", "Brown", "Red", "Blond")))
>  > hec.data
>        hair
> eye     Black Brown Red Blond
>   Green     5    29  14    16
>   Hazel    15    54  14    10
>   Blue     20    84  17    94
>   Brown    68   119  26     7
>  >
>
> but I want the result like below.:
>
> hair   eye counts
> Black Green    5
> Black Hazel   15
> Black  Blue   20
> Black Brown   68
> Brown Green   29
> Brown Hazel   54
> Brown  Blue   84
> Brown Brown  119
> Red Green     14
> Red Hazel     14
> Red  Blue     17
> Red Brown     26
> Blond Green   16
> Blond Hazel   10
> Blond  Blue   94
> Blond Brown    7
>
> How can I do it. Thanks you for your help.
>
> Best regards,
> Muhammad Subianto
>
> ______________________________________________
> 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




More information about the R-help mailing list