Displaying 20 results from an estimated 30000 matches similar to: "More on tapply and factors"
2011 Jul 16
2
(unclassified?) Help Question
Dear List,
I'd appreciate you guidance for obtaining the desired result shown
below, by combining tapply(x, g, mean) and g in the example.
Basically, I'm trying to create a vector whose values are based on the
result from tapply(x, g, mean) but that follow the pattern and length
given by the factor g. Of course I'm looking for a generic solution
(i.e, not something that just work
2006 Nov 24
2
low-variance warning in lmer
For block effects with small variance, lmer will sometimes
estimate the variance as being very close to zero and issue
a warning. I don't have a problem with this -- I've explored
things a bit with some simulations (see below) and conclude that
this is probably inevitable when trying to incorporate
random effects with not very much data (the means and medians
of estimates are plausibly
2003 Dec 08
1
aggregate and names of factors
Hello,
I use the function 'aggregate' a lot.
One small annoyance is that it is necessary to name the factors in the
'by' list to get the names in the resulting data.frame (else, they
appear as Group.1, Group.2...etc). For example, I am forced to
write:
aggregate(y,list(f1=f1,f2=f2),mean)
instead of aggregate(y,list(f1,f2),mean)
(for two factors with short names, it is not such
2009 Oct 15
1
tapply() and using factor() on a factor
Dear List,
Shouldn't result1 and result2 be equal in the following case?
Note that log$RequestID is a factor. That is, is.factor(log$RequestID)
yields TRUE.
result1 <- tapply(log$Flag,factor(log$RequestID),sum)
result2 <- tapply(log$Flag,log$RequestID,sum)
Yet, when I summarize the output, I get the following:
summary(result1)
Min. 1st Qu. Median Mean 3rd Qu.
2009 Sep 16
3
apply function across two variables by mult factors
Greetings,
I am attempting to run a function, which produces a vector and
requires two input variables, across two nested factor levels. I can
do this using by(X, list(factor1, factor2), function), however I
haven't found a simple way to extract the list output into an
organized vector form. I can do this using nested loops but it isn't
exactly an optimal approach.
Thank you
2011 Apr 25
1
average among one factor in a nested dataframe
I have two nested data frames:
a<-rnorm(6)
b<-rnorm(9)
f1<-c("x1","x2","x3"))
f2<-c("y1","y2")
id<-c(1:6)
a_df<-data.frame(cbind(id,f1,"y1",a))
id<-c(1:9)
b_df<-data.frame(cbind(id,f1,"y2",b))
I want to preserve id and f1, but want to collapse f2 and take the
corresponding mean values of a and b.
2013 Oct 12
2
Order of factors with facets in ggplot2
Hello,
I'd like to produce a ggplot where the order of factors within facets is
based on the average of another variable.
Here's a reproducible example. My problem is that the factors are ordered
similarly in both facets. I would like to have, within each facet of `f1',
boxplots for 'x' within each factor `f2', where the boxplots are ordered
based on the average of x
2013 Oct 14
1
R Help-how to use sapply w/tapply
Hi,
(Please use ?dput() to share the example dataset. Avoid using images to show dataset. Also, please read the posting guide esp. regarding home work, assignments etc.)
res <- sapply(Gene[,-1],function(x) tapply(x,list(Gene$Genotype),mean))
#or
res2 <-? aggregate(.~Genotype, data=Gene,mean)
#or
library(plyr)
?res3 <- ddply(Gene,.(Genotype),numcolwise(mean))
identical(res2,res3)
2007 Jun 04
3
test for nested factors
Is there a conventional way to test for nested factors? I.e., if 'a'
and 'b' are lists of same-length factors, does each level specified by
'a' correspond to exactly one level specified by 'b'?
The function below seems to suffice, but I'd be happy to know of a more
succinct solution, if it already exists.
Thanks,
Tim.
---
"%nested.in%" <-
2011 Sep 27
1
Does replacing some values of a zoo object by NA reduce it's size ?
Dear R-helpers,
Please have a look at the following. f1 is the same as f2 except that it has
some values replaced by NA. But it's corresponding file is slightly bigger
than the file containing f2. Could someone please tell me if this is an
anomaly ?
> load("file1")
> ls()
[1] "f1"
> load("file2")
> ls()
[1] "f1" "f2"
>
>
2005 Jun 28
2
boxplot by factor (Package base version 2.1.1) ( PR#7976)
The issue is not with boxplot, but with split. boxplot.formula()
calls boxplot(split(split(mf[[response]], mf[-response]), ...),
but look at what split() returns when there are empty levels in
the factor:
> f <- factor(gl(3, 6), levels=1:5)
> y <- rnorm(f)
> split(y, f)
$"1"
[1] 0.4832124 1.1924811 0.3657797 1.7400198 0.5577356 0.9889520
$"2"
[1] -1.1296642
2024 Mar 27
1
Output of tapply function as data frame
Warm greetings to you all.
Using the tapply function below:
data<-read.table("FD1month",col.names = c("Dates","count"))
x=data$count
f<-factor(data$Dates)
AB<- tapply(x,f,mean)
I made a simple calculation. The result, stored in AB, is of the form
below. But an effort to write AB to a file as a data frame fails. When I
use the write table, it only produces
2024 Mar 29
1
Output of tapply function as data frame: Problem Fixed
?s 01:43 de 29/03/2024, Ogbos Okike escreveu:
> Dear Rui,
> Thanks again for resolving this. I have already started using the version
> that works for me.
>
> But to clarify the second part, please let me paste the what I did and the
> error message:
>
>> set.seed(2024)
>> data <- data.frame(
> + Date = sample(seq(Sys.Date() - 5, Sys.Date(), by = "1
2024 Mar 29
2
Output of tapply function as data frame: Problem Fixed
Dear Rui,
Thanks again for resolving this. I have already started using the version
that works for me.
But to clarify the second part, please let me paste the what I did and the
error message:
> set.seed(2024)
> data <- data.frame(
+ Date = sample(seq(Sys.Date() - 5, Sys.Date(), by = "1 days"), 100L,
+ TRUE),
+ count = sample(10L, 100L, TRUE)
+ )
>
> # coerce
1999 Jan 17
1
Other core dumps, with apologies
Norm Josephy <NJOSEPHY@bentley.edu> writes:
> Sir:
>
> I hope you do not mind me sending e-mail directly to you
> rather than to the developer's list. I wish to avoid
> unnecessary traffic on the list when the issue I raise may
> have already been fixed.
As a matter of principle: I *do* mind. One of the purposes of having a
list is that not everyone has the time
1999 Jan 17
1
Other core dumps, with apologies
Norm Josephy <NJOSEPHY@bentley.edu> writes:
> Sir:
>
> I hope you do not mind me sending e-mail directly to you
> rather than to the developer's list. I wish to avoid
> unnecessary traffic on the list when the issue I raise may
> have already been fixed.
As a matter of principle: I *do* mind. One of the purposes of having a
list is that not everyone has the time
2004 Jan 06
1
Grouping data.frames
Hello all,
I'm new to R (and the S language in general) so go easy on me if this is really simple.
Given a data.frame df which looks like this:
f1 f2 f3 f4 c1 c2
1 y y a b 10 20
2 n y b a 20 20
3 n n b b 8 10
4 y n a a 30 5
I'd like to aggregate it by the factors f1 and f2 (or f2 and f3, or any other combination of the three) and compute the sum of c1 and c2 (as separate values). I
2004 Mar 15
2
Bug in tapply with factors containing NAs (PR#6672)
Full_Name: George Leigh
Version: 1.8.1
OS: Windows 2000
Submission from: (NULL) (203.25.1.208)
The following example gives the correct answer when the first argument of tapply
is a numeric vector, but an incorrect answer when it is a factor. If the
function used by tapply is "length", the type and contents of the first argument
should make no difference, provided it has the same
1999 Nov 11
2
tapply not simplifying to vector? (PR#320)
Hi, all.
The help file for tapply says that if simplify is true, and the result of
the calculation is always a scalar, then tapply will return a vector.
Nonetheless:
> t1 <- tapply(runif(10), rep(1:5, 2), mean)
> is.vector(t1)
[1] FALSE
> is.array(t1)
[1] TRUE
>
I have found this in version 0.65.1 on an SGI running Irix 6.5, and on a
Mac running Linux-PPC. I've also
2001 Feb 21
1
Specification of factors in tapply
After some fiddling around with the tapply command, I discovered that the
factors (the INDEX argument) given to tapply must be specified in
fastest-cycling first order.
The following code shows how I discovered my error: (R version 1.2.1)
-o-o-o-o-o-
x <- as.data.frame(list(data=c(-9,0,3,1,-9,1,0,-9,0,3,1,-9,1,0),
subj=c(rep(1,7),rep(2,7)),