similar to: xtabs to dataframe fails (PR#3754)

Displaying 20 results from an estimated 10000 matches similar to: "xtabs to dataframe fails (PR#3754)"

2003 Nov 06
1
Question about computing offsets automatically
Hi, I'm using R version 1.8.0 on Windows NT. When fitting a glm with Poisson random component and a log link, I frequently need to include an offset. Typically I use xtabs or table to get the counts for the contingency table, and then I use as.data.frame.table to create a data frame that I can use in the glm function. I have not found an option that allows me to total the offset variable to
2007 Jan 09
1
contingency table analysis; generalized linear model
Dear List, I would appreciate help on the following matter: I am aware that higher dimensional contingency tables can be analysed using either log-linear models or as a poisson regression using a generalized linear model: log-linear: loglm(~Age+Site, data=xtabs(~Age+Site, data=SSites.Rev, drop.unused.levels=T)) GLM: glm.table <- as.data.frame(xtabs(~Age+Site, data=SSites.Rev,
2016 May 23
2
data frame method for as.table()
Hello, Currently it's possible to convert an object of class table to a data frame with as.data.frame.table(), but there's no ready-made function, AFAIK, to do the reverse operation, i.e. conversion of a data frame to a table. Do you think it would be a good idea to add a data.frame method to as.table(), to allow such conversions? The idea is that if `x' is a table and `y <-
2009 Dec 13
1
xtabs - missing combination
Dear list, I am trying to make a contingency table with xtabs but I am getting a 0 where I expect a 'NA'. Here is a simple example: options(stringsAsFactors = FALSE) rn <- LETTERS[1:4] df1 <- data.frame(r07 = rep(rn, each=4), r08 = rep(rn, 4), value = 1:16) xtabs(value ~ r07 + r08, df1) # Delete the combination [A, C] df1 <- df1[-3,] # Set 'value'
2008 Mar 29
1
Tabulating Sparse Contingency Table
I have a sparse contingency table (most cells are 0): > xtabs(~.,data[,idx:(idx+4)]) , , x3 = 1, x4 = 1, x5 = 1 x2 x1 1 2 3 1 0 0 31 2 0 0 112 3 0 0 94 , , x3 = 2, x4 = 1, x5 = 1 x2 x1 1 2 3 1 0 0 0 2 0 0 0 3 0 0 0 , , x3 = 3, x4 = 1, x5 = 1 x2 x1 1 2 3 1 0 0 0 2 0 0 0 3 0 0 0 , , x3 = 1, x4
2003 Apr 30
1
sorting factors
Hi, I've been trying to sort the values of the factors of contingency tables generated with xtabs. For example, I have a factor called "artic" with three possible values that I would like to order in a specific way -- but I'm not sure how to go about this. > test <- read.table("test.tab",header=TRUE,sep="\t") > artic =
2009 Apr 24
2
argument 'exclude' in function xtabs
Dear all I was willing to use argument 'exclude' in function xtabs to remove some levels of factors (xtabs help page says '"exclude: a vector of values to be excluded when forming the set of levels of the classifying factors"). I tried: > mydata <- data.frame( treatment = c("B", "A", "C", "C", "B",
2007 Oct 05
1
creating objects of class "xtabs" "table" in R
I have an application that would generate a cross-tabulation in array format in R. In particular, my application would give me a result similar to that of : array(5,c(2,2,2,2,2)) The above could be seen as a cross-tabulation of 5 variables with 2 levels each (could be 0 and 1). In this case, the data were such that each cell has exactly 5 observations. I Now, I want the output to look like the
2011 Aug 16
1
getting names of dimnames of xtabs into xtable latex output
In R, the output of xtabs displays the names of the dimnames. In the example below, these are "change_diet" and "mydiet". Is there a way to have xtable incorporate these names directly into the latex output. Thanks for your help. table2 <- structure(c(26, 0, 40, 0, 10, 0, 188, 0, 281, 0), .Dim = c(5L, 2L), .Dimnames = structure(list(change_diet = c("Don't
2005 Nov 17
1
transforming table into data frame
Hello, I would like to transform a contingency table (A x B) into a data frame while keeping the cross-tabulation structure (i.e. rows = levels of A, columns = levels of B). I have tried as.data.frame, xtabs, etc... and always got a "flattened" list of 3 variables (A, B, Freq). How to do that? Thanks in advance Charles Raux
2011 Jun 24
1
Converting an ftable (contingency table) to a dataframe in R
I am generating an ftable (by running ftable on the results of a xtabs command) and I am getting the following. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Var1? Var2 date ? ? ? ? ? ? ? ? group? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 2007-01-01? ? ? ? ? q1 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?1? ? 9 ? ? ? ? ? ? ? ? ? ? ?q2 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
2002 Feb 13
3
xtabs
Hi, In Splus if I call the function crosstabs() the output is a contigency table; in each cell of the table is printed: N, N/RowTotal, N/ColTotal, N/Total. N is the number of observations in each cell. The same call to xtabs() in R will produce the contigency table but the only entry in each cell is N. How can I get the same relative frequencies that crosstabs() gives? Thanks, mike --
2003 Dec 02
0
xtabs or model.frame (PR#5461)
# Your mailer is set to "none" (default on Windows), # hence we cannot send the bug report directly from R. # Please copy the bug report (after finishing it) to # your favorite email program and send it to # # r-bugs@r-project.org # ###################################################### Here is the bug report I got from Professor Hsuan, and my exploration of it. The cause of the
2003 May 14
2
how to include 'NA's in xtabs?
Hello! I have a dataset with NA's in some variables (factors), for example: $ P67 : Factor w/ 2 levels "-","+": NA 2 1 NA NA 2 1 1 2 NA ... I need to use 'xtabs' like xtabs(~x$P67) It works well and produces something like this: x$P67 - + 779 1318 but i want to compute NA's too, like this: x$P67 - + NA 779 1318 137 I am trying
2010 Nov 08
1
unknown dimensions for loglm
Dear R-help community, I am working with multidimensional contingency tables and I am having trouble getting loglm to run on all dimensions without typing out each dimension. I have generated random data and provided output for the results I want below: d1.c1 <- rnorm(20, .10, .02) d1.c2 <- rnorm(20, .10, .02) d2.c1 <- rnorm(20, .09, .02) d2.c2 <- rnorm(20, .09, .02) d3.c1 <-
2009 Sep 04
1
Problem with xtabs(), exclude=NULL, and counting NA's
Hi all, I cannot get xtabs to count NA's like I expect. Below is a sample session, and note that the last two calls to xtabs() yield exactly the same thing. I am running R-2.5.0 -- if there was a bug in xtabs that got fixed, I would love to know about it. If there is a bug tracker somewhere, I can file it too. It isn't my fault that the server is so ridiculously outdated, but I would
2015 Feb 09
3
xtabs and NA
Hi I haven't found a way to produce a tabulation from factor data with NA values using xtabs. Please find a minimal example below, it's also on R-pubs [1]. Tested with R 3.1.2 and R-devel r67720. It doesn't seem to be documented explicitly that it's not supported. From reading the code [2] it looks like the relevant call to table() doesn't set the "useNA"
2005 Mar 22
1
List of tables rather than an extra dimension in the table or (l)apply(xtabs)
I'm not sure how to best explain what I am after but here goes. I have a data frame with 2 geographical factors. One is the major region the other is the component regions. I am trying to process all the regions at the same time without using "for". So I need (think, I do) a list of matrices each structured according to the number of subregions within each region. So is there a
2004 Nov 29
1
Seeking help with a simple loop construction
Hello, I have a df, pp, with five variables: > nobs(pp) q10_1 q10_2 q10_3 q10_4 actcode 1620 1620 1620 1620 1620 I want to create a loop to run four xtabs (the first four variables above by the fifth) and then store the results in a matrix. Below I make my intent clear by showing the output of one xtab which is inserted into a matrix. > a <- xtabs(q10_1 ~
2010 Apr 18
3
xtabs() of proportions, and naming a dimension (not a row)
Hi, xtabs() creates a table of counts. I want a table of proportions -- that is, I want to divide every vector (along a particular dimension) by its sum. The tiny example below does that. The call to xtabs() creates a matrix "A" with dimensions ("x1","x2","y"). I transform "A" using aperm() and aaply() to get the matrix "B". The