Displaying 20 results from an estimated 10000 matches similar to: "extracting index list when using tapply()"
2008 Jul 08
0
Fwd: Re: extracting index list when using tapply()
The following message is provided by Erik
Please provide the reproducible code to do this. Generate a sample data
set using the random data generating functions and show us what you'd
like, we can then more easily help.
ctu at bigred.unl.edu wrote:
> Hi,
> How about using "subset"?
> x1<-tapply(subset(years, length(area)>20), function(x) length(unique(x)))
>
2009 Aug 13
2
glm.nb versus glm estimation of theta.
Hello,
I have a question regarding estimation of the dispersion parameter (theta)
for generalized linear models with the negative binomial error structure. As
I understand, there are two main methods to fit glm's using the nb error
structure in R: glm.nb() or glm() with the negative.binomial(theta) family.
Both functions are implemented through the MASS library. Fitting the model
using these
2004 May 13
2
tapply & hist
I'm learning how to use tapply.
Now I'm having a go at the following code in which dati contains almost 600
lines, Pot - numeric - are the capacities of power plants and SGruppo - text
- the corresponding six technologies ("CCC", "CIC","TGC", "CSC","CPC", "TE").
.....................................................
2007 Nov 06
1
A suggestion for an amendment to tapply
Dear R-developers,
when tapply() is invoked on factors that have empty levels, it returns
NA. This behaviour is in accord with the tapply documentation, and is
reasonable in many cases. However, when FUN is sum, it would also
seem reasonable to return 0 instead of NA, because "the sum of an
empty set is zero, by definition."
I'd like to raise a discussion of the possibility of an
2010 Feb 02
3
tapply for function taking of >1 argument?
I'm sure I can put this together from the various 'apply's and split, but I
wonder if anyone has a quick incantation:
E.g. I can do tapply( data, groups, mean)
but how can I do something like: tapply( list(data,weights), groups,
weighted.mean ) ?
(or: mapply is to sapply as ? is to tapply )
Thanks for your help.
--
View this message in context:
2012 Sep 03
1
Scatter plot from tapply output, labels of data
Hei,
i am trying to plot the means of two variables (d13C and d15N), by 2
grouping factors (Species and Year) that i obtained by the function tapply.
I would like to plot with different colours according to the Year and show
the "Species" as data labels.
My data looks like this:
Species d13C d13N Year
"Species1" 14,4 11.5 2009
"Species2"
2008 Nov 14
1
# values used in a function in tapply
Hello,
I am using tapply to pull out data by the day of week and then perform
functions (e.g. mean). I would like to have the number of values used for
the calcuation for the functions, sorted by each day of week. A number of
entries in any given column are NAs.
I have tried the following code and simple variants with no luck.
for (i in 1:length(a[1,])){
x<-tapply(a[,i],a[,1],mean,
2007 Jun 18
1
getting tapply() to work across multiple columns
I have the following data.frame:
index <- c("a","a","b","b","b")
alpha <- c(1,2,3,4,5)
beta <- c(2,3,4,5,6)
table <-data.frame(index,alpha,beta)
I'm now interested in getting means of alpha and beta for each of the
index values and do a tapply() for each of the columns, e.g.
means.alpha <- tapply(table$alpha, index,mean)
2008 Sep 01
1
how to pass additional parameters to a function called in tapply?
Hi all,
the following problem is still beyond my R-knowledge:
I have one data vector containing the signal from 4 channels that are measured
subsequently and in repeating cycles (with one factor vector for cycle and
one for channel identification).
To extract the mean of each channel during each cycle tapply is the method of
choice. However, I cannot use the whole measuring period for each
2008 Sep 28
2
using tapply on a data frame in a function
Hello,
I'm trying to use tapply to find group means in a function. It works
outside of a function, but I get the error message from the following code:
"Error in tapply(index, cluster, mean) : arguments must have same length."
Any suggestions? Thanks.
eric
d <- data.frame(cbind(cluster=1:2, value1=1:10, value2=11:20))
d
FindClusterTraits <- function(framename, index){
2017 Jan 27
1
RFC: tapply(*, ..., init.value = NA)
The "no factor combination" case is distinguishable by 'tapply' with simplify=FALSE.
> D2 <- data.frame(n = gl(3,4), L = gl(6,2, labels=LETTERS[1:6]), N=3)
> D2 <- D2[-c(1,5), ]
> DN <- D2; DN[1,"N"] <- NA
> with(DN, tapply(N, list(n,L), FUN=sum, simplify=FALSE))
A B C D E F
1 NA 6 NULL NULL NULL NULL
2 NULL NULL 3 6
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
2009 Dec 01
1
Remark on tapply().
Consider the following:
> set.seed(42)
> ff <- factor(sample(c(1,3,5),42,TRUE),levels=1:5)
> x <- runif(42)
> tapply(x,ff,sum)
1 2 3 4 5
3.675436 NA 7.519675 NA 9.094210
I got bitten by those NAs in the result of tapply(). Effectively
one is summing over the empty set, and consequently (according to what
I learned as a child)
2011 Mar 15
1
Questions on dividing lists and tapply
Hello R community,
I have two questions about using R.
The first is about dividing each element of a list with another similar
sized list. So, if the first list has two elements and so does the second,
then the result should also be a list with two elements.
For example, the inputs are:
list(matrix(1:6,ncol=2),matrix(1:6,ncol=2))->l1
l2<-list(1:3,2)
I want to get a list, l3 with the
2009 Apr 13
3
tapply output as a dataframe
i use tapply and by often, but i always end up banging my head against
the wall with the output.
is there a simpler way to convert the output of the following tapply to
a dataframe or matrix than what i have here:
# setup data for tapply
dt = data.frame(bucket=rep(1:4,25),val=rnorm(100))
fn = function(x) {
ret =
c(unname(quantile(x,probs=seq(.25,.75,.25),na.rm=T)),mean(x,na.rm=T))
}
a =
2008 Sep 09
2
exporting tapply objects to csv-files
Dear Everyone,
I try to create a cvs-file with different results form the table function.
Imagine a data-frame with two vectors a and b where b is of the class factor.
I use the tapply function to count a for the different values of b.
tapply(a,b,table)
and I use the table function to have a look of the frequencies as a total
table(a)
I would like to put both results together in one txt or
2008 Aug 07
6
multiple tapply
Hi folk,
I tried this and it works just perfectly
tapply(iris[,1],iris[5],mean)
but, how to obtain a single table from multiple variables?
In tapply x is an atomic object so this code doesn't work
tapply(iris[,1:4],iris[5],mean)
Thanx and great summer holidays
Gianandrea
--
View this message in context: http://www.nabble.com/multiple-tapply-tp18868063p18868063.html
Sent from the R help
2005 Aug 08
1
tapply huge speed difference if X has names
Hi all,
Apologies if this has been raised before ... R's tapply is very fast, but if
X has names in this example, there seems to be a huge slow down: under 1
second compared to 151 seconds. The following timings are repeatable and
are timed properly on a single user machine :
> X = 1:100000
> names(X) = X
> system.time(fast<<-tapply(as.vector(X), rep(1:10000,each=10), mean))
2003 Jun 18
2
Private: Problem with tapply/lapply and sample (PR#3286)
Full_Name: Peter Gedeck
Version: R1.6.2 and R1.7.0
OS: Windows XP
Submission from: (NULL) (194.191.169.72)
Hello,
I marked the bug report Private, as I don't want my email address on the web
server. The problem that I found is best explained using an example.
index <- 1:6
cluster <- c(1,1,1,2,2,3)
tapply(index,cluster,sample)
gives
$"1"
[1] 2 1 3
$"2"
[1] 4 5
2012 Aug 29
5
tapply confusion
Hello
I have a huge data frame with three columns 'Roof' 'Month' and 'Temp'
i want to run analyses on the numerical Temp data by the factors Roof and
Month, separately and together.
For using more than one factor i understand i should use aggregate, but i am
struggling with the tapply for single factor analysis.
> tapply(Temp, INDEX = Roof, FUN = median)
This works