Questions tagged [tapply]

tapply is a function in the R programming language for apply a function to subsets of a vector.

tapply is a function in the R programming language for apply a function to subsets of a vector. A vector is broken in to subsets, potentially of different lengths (aka a ragged array) based on the values of one or more other vector. The second vector is either already a factor or coerced to be a factor by as.factor. A function is applied to each of these subsets. tapply then returns either an array or a list, depending on the output of the function.

354 questions
0
votes
2 answers

Separate meta analyses by a variable

I am meta analyzing everything related to listening (e.g., listening and leadership, listening and job satisfaction, etc.). I would like to have all the effects in a single file and run separate meta analyses based on topic. [I have some 70…
Avi Kluger
  • 91
  • 6
0
votes
1 answer

Calculate mean value of subsets and store them in a vector for further analysis

Hullo, I've been working on a dataset for a while now, but am also kind of stuck. One question/answer here was already helpful, but I need to calculate the mean not for a single value, but sixty. My dataset is basically this: > data[c(1:5, 111:116),…
Temerity
  • 1
  • 2
0
votes
1 answer

What is the best way to summarize a distribution of data based on a categorical variable? I'm trying to model calls based on day of the week

I have a dataframe that contains Date, Day-of-the-Week (categorical), and number of calls (numeric). I'm trying to do analytics on how what the distribution of call volume is by Day-of-the-week. Using the lattice package I was able to create a bar…
Ryan Chase
  • 2,384
  • 4
  • 24
  • 33
0
votes
2 answers

Collapse a character vector by value in another column r

I have a dataframe with a set of character strings in one column, and a grouping variable (a string, but could be a factor) in another. I'd like to collapse the dataframe such that the strings are collapsed into elements by grouping-variable. For…
sjgknight
  • 393
  • 1
  • 5
  • 19
0
votes
3 answers

How to apply a custom function to each participant in a data frame

I created a function that calculates dPrime. The function takes a data frame as its argument. This works fine, however the columns must be called "stimDiff" and "stimSame", as the function calculates dPrime using these specific names. I would like…
babylinguist
  • 392
  • 1
  • 13
0
votes
2 answers

Insert NA's in case there are no observations when using subset() and then dcast or tapply

I have the following data frame (this is only the head of the data frame). The ID column is subject (I have more subjects in the data frame, not only subject #99). I want to calculate the mean "rt" by "subject" and "condition" only for…
ayalaall
  • 145
  • 2
  • 16
0
votes
1 answer

aggregate over 2 groups

I'm trying to understand how to aggregate my output. I've created some dummy data which approximates my actual data, which is: hundreds of group1, 3 levels of group2, and several dozen validation logicals. Apologies if this seems simple, I've hunted…
0
votes
2 answers

How to apply a function on subset of dataframe iteratively

I am trying to remove outlier from a dataframe one group at a time from the following dataframe: set.seed(1234) library('mvoutlier') x <- rnorm(10) # standard normal x[1] <- x[1] * 10 # introduce outlier y <- rnorm(10) # standard…
user1140126
  • 2,621
  • 7
  • 29
  • 34
0
votes
1 answer

syntax error while applying tapply to a vector

I was practicing the lectures of coursers on R programming, in one of the lectures where he demonstrates tapply() function I just copy pasted what is taught in the lectures but got a syntax error x <- c(norm(10),runif(10), rnorm(10,1)) f <-…
algoboy
  • 63
  • 6
0
votes
1 answer

Values for 'fun= ' in *apply functions

The *apply (apply, tapply, lapply etc.) are a very useful and straightforward method of applying a function across an array of data, with the generic structure: *apply(data, function ...) However, I cannot find a list of valid functions. Can…
Charles Brewer
  • 183
  • 2
  • 12
0
votes
2 answers

How to use "with" and "tapply" to calculate a new variable based on multiple factors

I'm trying to obtain the mean "ctrlmeans" of the telephone handle time "Handle" of a single group "Actrl" based on another a variable "Period". I then want to create a new variable "Difference" by subtracting that mean from the "Handle" of each…
user3594490
  • 1,949
  • 2
  • 20
  • 26
0
votes
1 answer

Adding same observations from 2 different groups. Plyr or tapply?

Looking to create a function. I would like to add the number of occurrences of an observation up within a given group (ex 5, 5 occurrences 2 times). The same numbers of Days within a Week by Business are to be summed. The summed values will be in a…
user3608523
  • 65
  • 1
  • 7
0
votes
3 answers

average of multiple numbers in R

say I generate a data with this code month<-c(rep(1,7),rep(2,7),rep(3,7)) date<-rep(c(rep(1,2),rep(2,3),rep(3,2)),3) value<-rnorm(21) df<-cbind(month,date,value)) so now i have something like this month date value [1,] 1 1…
0
votes
1 answer

Grouping a data frame and using apply

I currently have a data frame that looks like this... Year School AveragePoints 2012-2013 Alabama 2.5 2012-2013 Alabama 5.4 2012-2013 Alabama 10.4 2012-2013 Alabama 1.2 2012-2013 …
0
votes
1 answer

Why the parameter FUN in tapply is invalid combined with colwise

I usually use the combination of colwise and tapply to calculate grouped values in a data frame. However, I found unexpectedly that the parameter FUN in tapply cannot work correctly with colwise from plyr. The example is as follows: Data: df <-…