Displaying 20 results from an estimated 10000 matches similar to: "Percentages and lattice"
2008 Oct 05
1
barchart for aggregated (sum) data in lattice?
Hi list,
I have data in a dataframe t1, with a column for different amounts
spent, a column what it was spent on, and a column with dates, from
which I create a new column with months.
Example:
amount <- rep(c(10,20,30),3)
what <- rep(c("food","books","cycling"),3)
when <- c(rep("2008-09-05",5),rep("2008-10-07",4))
t1 <-
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",
2009 Nov 17
1
lattice barchart
I have a data frame with two factors and want to create panel barcharts with
one factor defining the panels and the other the vertical categories by
which I can count the rows of data in each combination of factors. How do I
do this?
I have been trying to use barchart(~factor1|factor2) but it does not give
the panels as I want them.
The data looks like this:
Factor1 Factor2
A y
B
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
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"
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
2008 Jan 24
1
Filling data frame data into a matrix - please help
Dear group,
I have a data.frame (d1) with various elements and a
matrix (m1) created with NA (or 1s). I want to read
each row,column in d1 and fill its numeric value in
m1.
Could some one help me because I have 130K rows and
500 column data.frame object and I was told that a for
loop will take a long time.
Thank you.
> r1 <- c("A","A","B","B")
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",
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
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 Aug 14
2
Simple (?) subset problem
I can't figure out the syntax I need to get subset to work. I'm trying
to split my dataframe into two parts. I'm sure this is a simple issue,
but I'm stumped. I either get all or none of the original "rows".
> XTTable <- xtabs( ~ direction_ , SurveyData)
> XTTable
direction_
EASTBOUND
2008 Nov 05
1
How do I read a text (.csv) file to match a matrix/cross tab? (Object confusion??)
I'm having a problem reading data to set control totals for a dataframe.
I want to adjust a dataframe based on a 2-d table of values, which I get
by using :
> CurrentX1Sums <- as.matrix(xtabs(~tripid_nu+lineon, data=SurveyData))
> CurrentX2Sums <- apply(CurrentX1Sums, 1, sum)
I've created a .csv file with new (target) sums that looks like this:
tripid_nu Warner
2009 May 31
1
Bug in gmodels CrossTable()?
Is the code below showing a bug in Crosstable()? My expectation was that
the values produced by xtabs were rounded instead of truncated:
library(gmodels)
abc <- c("a", "a", "b", "b", "c", "c")
def <- c("d", "e", "f", "f", "d", "e")
wgt <- c(0.8, 0.6, 0.4, 0.5, 1.4, 1.3)
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
2009 Jan 14
2
Windows installer text bug (PR#13445)
Full_Name: Rob Cranfill
Version: 2.8.1
OS: Windows XP SP2
Submission from: (NULL) (130.76.32.19)
Using the Windows installer for 2.8.1, partway through the process there is a
dialog that looks something like this:
----------------------------------------------
Display Mode
Do you prefer the MDI or SDI interface?
-------
Please specify MDI or SDI, then click Next.
(*) MDI (one big
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
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 <-
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()
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
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 =