[R] Freq in dataframe

peter dalgaard pdalgd at gmail.com
Fri Aug 5 15:08:48 CEST 2016


You want to use the as.data.frame method for tables, so

> ddat <- as.table(ddat)
> as.data.frame(ddat)
      Time   Dose Group Freq
1  Week 32 Dose 1     A    8
2  Week 52 Dose 1     A   10
3  Week 32 Dose 2     A    7
4  Week 52 Dose 2     A   13
5  Week 32 Dose 3     A    8
6  Week 52 Dose 3     A   15
7  Week 32 Dose 1     B    7
8  Week 52 Dose 1     B    9
9  Week 32 Dose 2     B    6
10 Week 52 Dose 2     B    9
11 Week 32 Dose 3     B    7
12 Week 52 Dose 3     B   10
13 Week 32 Dose 1     C   11
14 Week 52 Dose 1     C   13
15 Week 32 Dose 2     C    7
16 Week 52 Dose 2     C   16
17 Week 32 Dose 3     C    8
18 Week 52 Dose 3     C   16

-pd

On 05 Aug 2016, at 11:43 , Tripoli Massimiliano <M.Tripoli at aifa.gov.it> wrote:

> Dear R users,
> 
> # This is my data:
> 
> ddat <- array(c(8,10,7,13,8,15,
>              7,9,6,9,7,10,
>               11,13,7,16,8,16
>               ),
>              dim = c(2,3,3),
>               dimnames = list(
>              Time = c("Week 32","Week 52"),
>               Dose = c("Dose 1","Dose 2","Dose 3"),
>             Group = c("A","B","C")))
> ddat
> 
> # and I'd like to have data like that:
> 
> as.data.frame(UCBAdmissions)
> 
> # I tried with 
> 
> as.data.frame(ddat) 
> 
> # and this is the result:
> 
>> as.data.frame(ddat)
>        Dose 1.A Dose 2.A Dose 3.A Dose 1.B Dose 2.B Dose 3.B Dose 1.C Dose 2.C Dose 3.C
> Week 32        8        7        8        7        6        7       11        7        8
> Week 52       10       13       15        9        9       10       13       16       16
> 
> Someone could help me ?
> Thanks in advance,
> 
> M. Tripoli
> _________________________
> 
> Dott. Massimiliano Tripoli
> Ufficio Assessment Europeo - European Assessment Office 
> Agenzia Italiana del farmaco - Italian Medicine Agency
> Via del Tritone 181 - 00187 Roma
> Tel. +39-06-59784643
> E-mail: m.tripoli at aifa.gov.it
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list