Hi, I used this command to produce a table: (tab1 = ftable(SEX, ESTCIV, Q1)) Q1 B L M N SEXO ESTCIV F A 11 13 4 2 E 1 0 0 0 M A 5 0 3 1 E 0 0 0 0 but I need something like: SEXO ESTCIV B L M N F A 11 13 4 2 F E 1 0 0 0 M A 5 0 3 1 M E 0 0 0 0 How can I get it? I need this format to use ordinal logistic regression and I have many tables. Thanks, Silvano. --- Este email está limpo de vírus e malwares porque a proteção do avast! Antivírus está ativa. [[alternative HTML version deleted]]
Hi, Try: library(reshape2) dcast(as.data.frame(tab1), SEX+ESTCIV~Q1,value.var="Freq") ##not tested. A.K. On Friday, December 20, 2013 8:03 AM, "silvano at uel.br" <silvano at uel.br> wrote: Hi, I used this command to produce a table: (tab1 = ftable(SEX, ESTCIV, Q1)) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Q1? B? L? M? N SEXO? ? ESTCIV ? ? ? ? F? ? ? ? ? A? ? ? ? 11 13? 4? 2 ? ? ? ? ? ? ? ? ? ? ? E? ? ? ? ? 1? 0? 0? 0 ? ? ? ? M? ? ? ? ? A? ? ? ? ? 5? 0? 3? 1 ? ? ? ? ? ? ? ? ? ? ? E? ? ? ? ? 0? 0? 0? 0 but I need something like: SEXO? ? ESTCIV? ? ? ? B? L? M? N ? ? ? F? ? ? ? ? ? A? ? ? ? 11 13? 4? 2 ? ? ? F? ? ? ? ? ? E? ? ? ? ? 1? 0? 0? 0 ? ? ? M? ? ? ? ? A? ? ? ? ? 5? 0? 3? 1 ? ? ? M? ? ? ? ? E? ? ? ? ? 0? 0? 0? 0 How can I get it? I need this format to use ordinal logistic regression and I have many tables. Thanks, Silvano. --- Este email est? limpo de v?rus e malwares porque a prote??o do avast! Antiv?rus est? ativa. ??? [[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.
What does your original data look like? I seems to me that it would be better to give us that information since you may not want to use ftable() at all. Ideally you should give us the original data or a sample of it. If it's confidential just replace the actual values with fake data. The structure of the data is more important than the values. Please use dput() (see ?dput for information) to supply the data. Just do : dput(mydata) and then paste the result into the email. John Kane Kingston ON Canada> -----Original Message----- > From: silvano at uel.br > Sent: Fri, 20 Dec 2013 11:01:26 -0200 > To: r-help at r-project.org > Subject: [R] ftable and data.frame > > Hi, > > I used this command to produce a table: > > (tab1 = ftable(SEX, ESTCIV, Q1)) > > Q1 B L M N > SEXO ESTCIV > F A 11 13 4 2 > E 1 0 0 0 > M A 5 0 3 1 > E 0 0 0 0 > > but I need something like: > > > SEXO ESTCIV B L M N > F A 11 13 4 2 > F E 1 0 0 0 > M A 5 0 3 1 > M E 0 0 0 0 > > How can I get it? > > I need this format to use ordinal logistic regression and I have many > tables. > > Thanks, > > Silvano. > > --- > Este email esta limpo de vmrus e malwares porque a protegco do avast! > Antivmrus esta ativa. > > > [[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.____________________________________________________________ FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
On Dec 20, 2013, at 5:01 AM, <silvano at uel.br> wrote:> Hi, > > I used this command to produce a table:It's not actually a 'table'.> > (tab1 = ftable(SEX, ESTCIV, Q1))is.table(tab1) # will return FALSE> > Q1 B L M N > SEXO ESTCIV > F A 11 13 4 2 > E 1 0 0 0 > M A 5 0 3 1 > E 0 0 0 0 > > but I need something like: > > > SEXO ESTCIV B L M N > F A 11 13 4 2 > F E 1 0 0 0 > M A 5 0 3 1 > M E 0 0 0 0 > > How can I get it?You need to describe the purpose of this effort. If is for display, the answer will be to look at the code for `print.ftable` (which eventually passes its arguments to `format.ftable`. If it is for creating something other than an ftable (such a data.frame or character-matrix), then you will probably need to coerce the ftable to a matrix to get the entry values and then extract the row labels from the 'tab1'-object with: attr(tab1, "row.vars") and `rep` them approriately. Or you could work with the output from format(ftable(tab1))[ ,1:2]. cbind( format(ftable(Titanic), quote=FALSE)[ ,1:3], format(ftable(Titanic), quote=FALSE)[ ,5:6]) [,1] [,2] [,3] [,4] [,5] [1,] " " " " " " " No" "Yes" [2,] "Class" "Sex " "Age " " " " " [3,] "1st " "Male " "Child" " 0" " 5" [4,] " " " " "Adult" "118" " 57" [5,] " " "Female" "Child" " 0" " 1" [6,] " " " " "Adult" " 4" "140" [7,] "2nd " "Male " "Child" " 0" " 11" [8,] " " " " "Adult" "154" " 14" [9,] " " "Female" "Child" " 0" " 13" [10,] " " " " "Adult" " 13" " 80" [11,] "3rd " "Male " "Child" " 35" " 13" [12,] " " " " "Adult" "387" " 75" [13,] " " "Female" "Child" " 17" " 14" [14,] " " " " "Adult" " 89" " 76" [15,] "Crew " "Male " "Child" " 0" " 0" [16,] " " " " "Adult" "670" "192" [17,] " " "Female" "Child" " 0" " 0" [18,] " " " " "Adult" " 3" " 20"> > I need this format to use ordinal logistic regression and I have many tables.That makes me think using ftable is the completely misguided approach. You should describe in more detail you plans to use ordinal logistic regression. I'm also wondering if you have used attach(). It would make more sense to keep these variables in a dataframe. Almost all regression functions expect input in the form of a normalized dataframe rather than in separate variables of aggregated counts.> (tab1 = ftable(SEX, ESTCIV, Q1)) > > Thanks, > > Silvano. > > --- > Este email est? limpo de v?rus e malwares porque a prote??o do avast! Antiv?rus est? ativa. > > > [[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.David Winsemius Alameda, CA, USA