similar to: getting tapply() to work across multiple columns

Displaying 20 results from an estimated 40000 matches similar to: "getting tapply() to work across multiple columns"

2010 Jun 04
1
tapply help
Dear R gurus, I am trying perform what I believe will be a pretty simple task, but I'm struggling to figure out how to do it. I have two vectors of the same length, the first is numeric and the second is factor. I understand that tapply is perfect for applying a function to the numeric vector by subsets of the factors in the second vector. My issue is trying to make use of two other vectors
2008 Jan 27
1
tapply on empty data.frames (PR#10644)
Full_Name: Hilmar Berger Version: 2.4.1/2.6.2alpha OS: WinXP Submission from: (NULL) (84.185.128.110) Hi all, If I use tapply on an empty data.frame I get an error. I'm not quite sure if one can actually expect the function to return with a result. However, the error message suggests that this case does not get handled well. This happens both in R-2.4.1 and 2.6.2alpha (version 2008-01-26).
2008 Dec 11
1
How do I tapply to a data frame with arbitrary column labels?
I have a data file that looks like this class pigeon falcon propeller jet wing fly birds 25 37 0 0 2 1 planes 0 1 28 40 1 3 birds 19 41 0 1 4 6 planes 0 0 25 50 5 5 planes 1 0
2007 Oct 05
4
Replacing NA values when building matrix using tapply
Hi, I'm building a matrix m from a data frame d which includes the matrix row, column and value. This works well enough: m <- tapply(d[,"value"],d[,c("row","column")],c) However, I'd like to replace any missing values with 0, not NA. The obvious doesn't work, however: m <-
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
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
2017 Feb 01
1
RFC: tapply(*, ..., init.value = NA)
On 'aggregate data.frame', the URL should be https://stat.ethz.ch/pipermail/r-help/2016-May/438631.html . vector(typeof(ans)) (or vector(storage.mode(ans))) has length zero and can be used to initialize array. Instead of if(missing(default)) , if(identical(default, NA)) could be used. The documentation could then say, for example: "If default = NA (the default), NA of appropriate
2013 Mar 11
2
aggregate(), tapply(): Why is the order of the grouping variables not kept?
Dear expeRts, The question is rather simple: Why does aggregate (or similarly tapply()) not keep the order of the grouping variable(s)? Here is an example: x <- data.frame(group = rep(LETTERS[1:2], each=10), year = rep(rep(2001:2005, each=2), 2), value = rep(1:10, each=2)) ## => sorted according to group, then year aggregate(value ~ group + year, data=x,
2008 Aug 01
3
Newbie question: How to use tapply() on several vectors simultaneously
Dear R users, I have a newbie-question that I couldn't resolve after reading through several pieces of documentation and searching the archive. I have a data.frame containing experimental data from a group experiment in psychology. Each line represents a single participant, but participants were assigned to groups of three or four persons. One variable indicates each participants'
2017 Jan 31
1
RFC: tapply(*, ..., init.value = NA)
Function 'aggregate.data.frame' in R has taken a different route. With drop=FALSE, the function is also applied to subset corresponding to combination of grouping variables that doesn't appear in the data (example 2 in https://stat.ethz.ch/pipermail/r-devel/2017-January/073678.html). Because 'default' is used only when simplification happens, putting 'default' after
2002 Jan 24
5
aggregate, by tapply
Dear R users I searched some sources but i did not find an answer.Please give me some hint to following problem. I would like to compute a summary statistic for some vector for different factor levels. I know I can use tapply or aggregate but I do not know if there is a way how to use function with several (two) variable input (like weighted.mean). I wrote a simple a function for factor
2010 Oct 06
3
tapply output
Hello, I am having trouble getting the output from the tapply function formatted so that it can be made into a nice table. Below is my question written in R code. Does anyone have any suggestions? Thank you. Geoff #Input the data; name <- c('Tom', 'Tom', 'Jane', 'Jane', 'Enzo', 'Enzo', 'Mary', 'Mary'); year <- c(2008, 2009,
2010 Aug 16
2
re-order the rows of a data frame accroding to a specified order of some column
Dear all, I have a data frame with several columns, and I have the specified order of a given column. How can I re-order the rows of my data frame accroding to this specified order? for example, x = data.frame( num = 1:26, alpha = letters[1:26], stringsAsFactors=FALSE) z = sample(x$alpha, replace=FALSE) Can I re-order x accroding to z ? Thanks, Leon [[alternative HTML version
2008 May 02
2
Coercing by/tapply to data.frame for more than two indices?
Dear Colleagues, Apologies for a long email to ask what I feel may be a very simple question; I figure it's better to overspecify my situation. I was asked a question, recently, by a colleague in my department about pre-aggregating variables, i.e., computing the mean of defined subsets of a data frame. Naturally, I thought of the 'by' and 'tapply' functions, as
2008 Sep 29
2
adding labels to tapply results
Hi, How do I get labels onto the output from tapply? I need the labels to merge the output with another data frame. Thanks. eric d <- data.frame(cbind(x=1:3, y=1:10)) a <- with(d, tapply(y, x, sum)) [[alternative HTML version deleted]]
2006 Feb 11
2
aggregate vs tapply; is there a middle ground?
Dear all, I'm wanting to do a series of comparisons among 4 categorical variables: a <- aggregate(y, list(var1, var2, var3, var4), sum) This gets me a very nice 2-dimensional data frame with one column per variable, BUT, as help for aggregate says, <<empty subsets are removed>>. I don't see in help(aggregate) how I can change this. In contrast, a <- tapply(y,
2004 Sep 01
2
using hist() with tapply()
Hi, I've been passing the hist() function to tapply() to quickly generate histograms based on the list of factors supplied to tapply(). However, I have not figured out how to generate titles for each of the histograms, which paste in the unique values of the list factors as part of the histogram title. I'm hoping that someone can tell me how to do this. Thanks for your time and
2003 Apr 17
3
accessing current factor in tapply
G'Day, I want to access in a function called from tapply the current factor. In my example below, all I want to do is to write the current factor on each histogram. Needless to say my example does not work. I would be grateful for pointers in the right direction. Many thanks Bernie McConnell Sea Mammal Reserach Unit cc <- 1:10 ff <- rep(c("a","b"),5) pp<-
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