Displaying 20 results from an estimated 467 matches for "xtabs".
Did you mean:
tabs
2001 Aug 21
4
looking for a smarter way
I have two problems where I've come up with some code that will do the
analysis that I want, but it looks pretty clumsy. In the first case, I
calculate the variance on five different columns for each of 14 clusters and
get them into one matrix. I get the job done, but I would have thought that
it could be done in one or two lines, not six, and be generalized so that it
didn't matter how
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 xtabs(~x$P67, exclude=NULL) but xtabs does not compute
'NA's in this case too.
I do not wan...
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" par...
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", &qu...
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
is...
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 t...
2017 Jan 19
2
xtabs(), factors and NAs
Hi all,
I know this issue has been discussed a few times in the past already,
but Martin Maechler suggested in a bug report [1] that I raise it here.
Basically, there is no (easy) way of printing NAs for all variables
when calling xtabs() on factors. Passing 'exclude=NULL,
na.action=na.pass' works for character vectors, but not for factors.
> test <- data.frame(x=c("a",NA))
> xtabs(~ x, exclude=NULL,
na.action=na.pass, data=test)
x
a?
1?
> test <- data.frame(x=factor(c("a",NA)))
> xt...
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 &l...
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 <-
2016 May 23
0
data frame method for as.table()
...1
>> (yy <- as.data.frame(y))
> foo Freq
> 1 a 2
> 2 b 2
> 3 <NA> 1
>> as.table(yy)
> foo
> a b <NA>
> 2 2 1
>>
>
> Any thoughts?
Hi,
I have not tried an exhaustive set of examples, but I believe that ?xtabs will get you most of the way there, with the exception of NA handling, which would require either nuanced use of ?addNA or preprocessing factors in the input data frame to possibly add NA as a factor level where needed.
BTW, from ?as.data.frame.table, see the reference there to xtabs() at the end:...
2003 Aug 16
2
xtabs to dataframe fails (PR#3754)
Full_Name: Daniel Frey
Version: 1.7.1
OS: Windows 2000
Submission from: (NULL) (80.254.164.242)
Generating a data frame out of a xtabs result acts unusual. Take the following
sample to reproduce it:
> a.a <- c("a","a","a","b","b")
> a.b <- c("c","c","d","e","f")
> a.df <- data.frame(list("A"...
2007 Oct 05
1
creating objects of class "xtabs" "table" in R
...uld 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 output of 'xtabs' utility, so
that I can use this output inside 'loglm(MASS)'. In particular, I want
to add (variable) names to each dimension and indicate the levels that
correspond to each cell. The output from 'xtabs' for a data set of
this kind would look like:
> xtabs(~.,data)
, , x3 =...
2008 Mar 12
1
ftable and xtabs
Hoping someone can help me with xtabs and ftable. I'm trying to get a pair
of ftables (possibly more) next to each other. For example:
> dunhill_lights_xtab<-ftable(xtabs(grossedupobs ~ gender+age_group +
dunhill_lights, data = ciggs))
> dunhill_lights_xtab
dunhill_lights No Yes
ge...
2011 Aug 30
2
Showing zero frequencies with xtabs
? stato filtrato un testo allegato il cui set di caratteri non era
indicato...
Nome: non disponibile
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110830/7c33d4d0/attachment.pl>
2001 Apr 03
2
Parse error in xtabs
Greetings-
Using R 1.2.2 under linux, I get the following:
> l.agg<-xtabs(cbind(r.logic.interests, r.logic.morality,
+ r.logic.enlightened, r.logic.capacity,
r.logic.mediate)
+ ~ grouptype,
+ data=gt)
Error in parse(file, n, text, prompt) : parse error
I know the data are structured fine, as I can use all the elements in
ind...
2005 Jun 06
1
don't want xtab sorting "numeric" factors...
r-gurus,
I couldn't find an answer to this and after an hour or so of trying all
types or ways to do this, I've given up for now.
I'm having trouble getting the results from xtabs to generate
"unsorted" factors. I've generated a sample data.frame I want to
create a table from, using xtabs, and the results are presented below,
> temp
treatment itpa qmd tht
1 0 100 7.287263 3.362501
2 25 100 10.461070 4.118217
3 50 1...
2003 Dec 02
0
xtabs or model.frame (PR#5461)
...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 problem is that a character vector is not
coerced to factor by xtabs or model.frame.
Is it a bug? I think yes. Character vectors are so frequently
coerced to factor that it is reasonable to assume that it will happen
here. The documentation is ambiguous as ?xtabs says
formula: a formula object with the cross-classifying variables,
separated by `+'...
2001 Aug 05
2
xtabs, drop.unused.levels (PR#1041)
...,x86
Submission from: (NULL) (194.221.251.1)
As a newbie I'm not sure, whether this is a bug, but I don't know how to get
around this behaviour:
> x <- list("A"=rep(c(1:5),30),
+ "B"=c(rep(letters[1:3],30),rep(letters[2:4],20)))
> y <- as.data.frame(x)
> xtabs(~A+B,y)
B
A a b c d
1 6 10 10 4
2 6 10 10 4
3 6 10 10 4
4 6 10 10 4
5 6 10 10 4
> y <- subset(y,B!="d")
> xtabs(~A+B,y,drop.unused.levels=TRUE)
B
A a b c d
1 6 10 10 0
2 6 10 10 0
3 6 10 10 0
4 6 10 10 0
5 6 10 10 0
I'd expect "xtabs&qu...
2011 Jan 26
2
a problem with is.na
Hello,
I have observed the following odd behavior of "is.na( )" and hope someone
can give me an explanation
Example:
X1=rep(1:2,5)[-1]
X2=rep(1:5,rep(2,5))[-1]
y= runif(9)
y[3]=NA
xtabs(y~x1+x2)
Now
xtabs(is.na(y)~x1+x2) says that cell 2,2 is NA
x2
x1 1 2
1 0 0
2 0 1
3 0 0
4 0 0
5 0 0
Whereas
xtabs(!is.na(y)~x1+x2) says that all but cell 1,1 and 2,2 are not NA
x2
x1 1 2
1 0 1
2 1 0
3 1 1
4 1 1
5 1 1
An explanation will be much appriciated
2017 Jan 20
0
xtabs(), factors and NAs
..., 19 Jan 2017 13:58:31 +0100 writes:
> Hi all,
> I know this issue has been discussed a few times in the past already,
> but Martin Maechler suggested in a bug report [1] that I raise it here.
>
> Basically, there is no (easy) way of printing NAs for all variables
> when calling xtabs() on factors. Passing 'exclude=NULL,
> na.action=na.pass' works for character vectors, but not for factors.
>
[ yes, but your example below is *not* showing that ... so may be
a bit confusing !] {Reason: stringsAsFactors etc}
> > test <- data.frame(x=c("a",NA))...