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
1 answer

tapply and error summary statistics for some factors

I tried to find an explanation for the summary results when using with tapply. In the following example, the summary statistics are wrong for factor "Reg2". Could someone help us understand that behavior? > edf=data.frame(pri=c(8258, 14253, 11123,…
Robert
  • 5,038
  • 1
  • 25
  • 43
0
votes
1 answer

How to make a boolean variable from a summary statistic in a dataframe?

I want to make a boolean column which states whether or not each sample is a maximum. I made this function and used it with tapply: is.max <- function(x){ x <- data.frame(x) x$x <- round(x$x,5) x_max <- round(max(x),5) for(i in 1:nrow(x)) { …
plamtrue
  • 73
  • 10
0
votes
1 answer

I would like to calculate z-scores based on two factors, is there a way to do this?

I would like to calculate the z scores of a summed scale based on two factors: Gender, and Age group (four factors). How can I do that in R? I'm really new to R, and only started learning, I came across tapply(AgingData$StandMen,…
0
votes
2 answers

How to summarize date data by groups in R

I would like to summarize the following sample data into a new dataframe as follows: Population, Sample Size (N), Percent Completed (%) Sample Size is a count of all records for each population. I can do this using the table command or tapply.…
Keith W. Larson
  • 1,543
  • 2
  • 19
  • 34
0
votes
1 answer

Covert many lines in a specific line

I would like to transform this data: Sample Genotype Region sample1 A Region1 sample1 B Region1 sample1 A Region1 sample2 A Region1 sample2 A Region1 sample3 A Region1 …
user3091668
  • 2,230
  • 6
  • 25
  • 42
0
votes
1 answer

R - modify order of levels in tapply function

I have data which looks like the following nums r a 1 3 210 0 4 6 3891 1 9 8 891 1 1 3 321 1 8 1 32 0 etc etc etc I'd like to compute a few things, and was wondering if anyone can help…
CodeGuy
  • 28,427
  • 76
  • 200
  • 317
0
votes
1 answer

can i change the tapply into aggregate to get the same result?

dat=data.frame( year=c(rep(2007,5),rep(2008,3),rep(2009,3)), province=c("a","a","b","c","d","a","c","d","b","c","d"), sale=1:11) tapply(dat$sale,list(dat$year,dat$province),sum) a b c d 2007 3 3 4 5 2008 6 NA 7 8 2009 NA …
showkey
  • 482
  • 42
  • 140
  • 295
0
votes
1 answer

Calculate mean value of sets of 4 sub locations from multiple location from a larger matrix

I am doing a data analysis on wall thickness measurements of circular tubes. I have the following matrix: > head(datIn, 12) Component Tube.number Measurement.location Sub.location Interval Unit Start 1 In 1 …
r.j.mendel
  • 65
  • 1
  • 5
0
votes
1 answer

Identify INDICES value that 'breaks' by() [or, equivalently, tapply()]

When using the function by, at times I will have a data subset (as determined by the INDICES argument) that 'breaks' by (technically it breaks FUN which in turn breaks by). Is there a way to identify the 'bad' value of the list passed to INDICES?…
Jubbles
  • 4,450
  • 8
  • 35
  • 47
0
votes
1 answer

Passing arguments to a list in tapply

I'm new to R and having trouble with passing arguments to a function for a few days now. I have a function that uses tapply with a by statement in it, My dataset is in the form of list data frames,so the function is: Means =…
user2721827
  • 183
  • 1
  • 2
  • 7
0
votes
1 answer

How to apply function over columns of matrix by multiple factors in R?

this is a simple question, and I am sure it is easily solvable with either tapply, apply, or by, etc. However, I am still relatively new to this, and I would like to ask for advice. The problem: I have a data frame with say 5 columns. Columns 4 and…
coffeinjunky
  • 11,254
  • 39
  • 57
0
votes
1 answer

tapply function in R

I am trying to apply my moving average function to one variable as follow: Fonction.mm <- function(x) { filter(x, poids, sides=1, method="conv") } numero<-1:nrow(data) tapply(numero, data$td, Fonction.mm) data$td which is a character variable…
aleeyah
  • 1
  • 1
  • 3
0
votes
1 answer

Using tapply on two columns instead of one

I would like to calculate the gini coefficient of several plots with R unsing the gini() function from the package reldist. I have a data frame from which I need to use two columns as input to the gini function. > head(merged[,c(1,17,29)]) idp…
Tom
  • 61
  • 6
0
votes
0 answers

counterpart of tapply in winbugs

I need to calculate the mean of each state. In R, I did this by using tapply(y,state,mean). Here is an example: state <- rbinom(10,4,0.6) y <- rnorm(10) tapply(y,x,mean) where y represent the vector of the fitted values and state represent the…
Günal
  • 751
  • 1
  • 14
  • 29
0
votes
1 answer

week day week-percent from time-series

I have some daily time-series data that i need to extract the 'week day percent' relative to the week mean. For example, if the first week has mean = 100 and the Sunday value for this week is 20, then sunday becomes 0.2. Here's some random…
Fernando
  • 7,785
  • 6
  • 49
  • 81