Displaying 20 results from an estimated 5000 matches similar to: "how to include 'NA's in xtabs?"
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"
2002 Oct 30
1
help needed. Why R does not produce lattice graphics when running command 'source (file_name)'?
Hi!
I have a source file - for example 'my.R' - which uses some functions from
'lattice' library.
It looks like that:
library(lattice)
pr<-xtabs(W~ff$'q1'+ff$'q2',data=ff)
pr<-pr/rowSums(pr)*100
pr<-as.data.frame(pr)
barchart(pr[[2]]~pr[[3]]|pr[[1]], horizontal=TRUE, as.table=TRUE,
xlab=NULL, ylab=NULL, col="plum",
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 <-
2009 Feb 19
1
How do I get xtabs to show missing data?
I presume the behavior below (no Connector values in the second table)
is because I have na values in my dataframe. How do I get them to list?
I found references to na.action and na.pass, but I could not figure out
how I could use them with xtabs to list the na as a value. I'm sure
there's a simple syntax I need, but it's not obvious to me.
> # Weighted Data
2003 May 17
1
how to handle 'multiresponse' variable?
Hello!
I have dataset where one variable is 'multiresponse', like this:
[1] "1 2" "1 2 3" "4" "1 4" "4 3" etc.
'responses' separated by space. observations in different 'rows'
of data.frame.
I can do strsplit(data$var,' ') and make a list, where multiple
responses are elements of character vectors, like this:
$
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'
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",
2009 Oct 05
1
How to get NA's into the output of xtabs?
Dear all,
Lets say I have the following data frame:
> df1 <- data.frame(Show=c('Star Trek', 'Babylon 5', 'Dr Who'), Size=c(0.7, 0.0, 0.701), Date=as.Date(c('2007-08-03', '2007-08-03', '2007-08-03'), format='%Y-%m-%d'))
> df2 <- data.frame(Show=c('Star Trek', 'Dr Who', 'Torchwood'), Size=c(0.8, 0.85,
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
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
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
gender age_group
Female
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
individual xtabs()
2001 Aug 05
2
xtabs, drop.unused.levels (PR#1041)
Full_Name: Martin Lenze
Version: 1.3.0 22.06.2001
OS: win32,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
2009 Jul 02
1
From xtabs to matrix
Hi list,
is it possible convert the xtabs result
xtabs(breaks~tension+wool,data=warpbreaks)
wool
tension A B
L 401 254
M 216 259
H 221 169
to a simple matrix or data frame?
A B
L 401 254
M 216 259
H 221 169
Thanks a lot! Gianandrea
--
View this message in context: http://www.nabble.com/From-xtabs-to-matrix-tp24304588p24304588.html
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")
>
2011 Jun 15
1
Reshaping data with xtabs reorders my rows
Dear,
I have a data frame melted from a list of matrices (melt from reshape
package), then I impute some missing values and then want to tabulate
the data again to the array (or list, doesn't matter) of matrices form.
However when using xtabs function it orders my rows alphabetically and
apparently doesn't take "reorder = FALSE" option or anything like it.
Is there anything I
2010 Jan 20
1
Reshaping data with xtabs giving me 'extra' data
Dear all,
Lets say I have several data frames as follows:
> set.seed(42)
> dates <- as.Date(c("2010-01-19", "2010-01-20"))
> times <- c("09:30:00", "11:30:00", "13:30:00", "15:30:00")
> shows <- c("Red Dwarf", "Being Human", "Doctor Who")
>
> df1 <- data.frame(Date = dates[1],
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
2009 Jun 03
1
Still can't find missing data - How do I get NA in xtabs with factors?
The problem here is Table doesn't seem to have a way to weigh the data.
> ToyData
Data1 Data2 Data3 Weight
101 Sam Red Banana 1.1
102 Sam Green Banana 2.1
103 Sam Blue Orange 2.1
104 Fred Red Orange 2.1
105 Fred Green Guava 2.1
106 Fred Blue Guava 2.1
107 <NA> Red Pear 50.1
108 <NA> Green Pear 50.1
109 <NA> Blue