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

Using tapply on a list of data frames

I would like to use tapply on a list of data frames in oder to calculate sums for individual groups and then tabulate the occurence of the value 0. On an individual data frame I would do this: sums <- tapply(my_data_frame$V3, my_data_frame$V2,…
user10198023
-2
votes
2 answers

how to use tapply for repeated data in R

this is my dataframe: x day month 5 1 1 4 1 1 1 2 1 3 2 1 5 1 2 2 1 2 5 2 2 3 2 2 I need to take the sum of x values for each day in each month. I already have tried: tapply(DF$x, DF$day, max) but it is not giving the right answers.
Madamespring
  • 35
  • 1
  • 7
-2
votes
1 answer

R how to do multiple GLMs for each level for a factor in my data.frame?

Is there an appropriate way to do R style logistic regression where I avoid using loops, but I can have multiple regressions for each level in a particular factor? For example, assume df is 365 daily rows with a binary to say whether or not it…
JoeBass
  • 519
  • 7
  • 18
-2
votes
2 answers

tapply with non numeric values

I'm in a class learning R right now, and I'm stuck on a problem. We set up the following data frame: Column1=c(rep("control",300),rep("ConditionB",300),rep("ConditionC",300)) Column2=(900,mean=100,sd=10) data=data.frame(Column1,Column2) It runs…
-2
votes
3 answers

To pass the row number to another column

I have a dataframe. I need to find a minimum value in the 1st column for each value of the 2nd column. But I should return the value in the 3rd column from the same row as the minimum found in the 1st column. The first part seems is solved by…
-3
votes
2 answers

Print the 3rd number and all the elements divisible by 2

nums <- 1:20 result <- nums[fill the function] result Please anyone can tell me what function to use
-3
votes
2 answers

Group pairwise categories together

I am currently working with a dataset where loans are displayed with a purpose for the loan and an associated loan grade for each loan. The dataset is called loancase and one of the columns is the purpose while another column is grade. Below I have…
user1713336
  • 131
  • 5
  • 14
-3
votes
1 answer

using tapply in tapply

I have a big data.frame with genomic data. The data looks like this- colnames(df)=c("id","chr","start","end","log2") where id is the sample name, chr is the number of the chromosome, start and end give me the location on the chromosome, and log2 is…
T.G.
  • 743
  • 3
  • 6
  • 27
-7
votes
1 answer

multiply multiple column and find sum of each column for multiple values

I'm trying to multiply column and get its names. I have a data frame: v1 v2 v3 v4 v5 0 1 1 1 1 0 1 1 0 1 1 0 1 1 0 I'm trying to multiplying each column with other, like: v1v2 v1v3 v1v4 v1v5 and v2v3 v2v4 v2v5 etc,…
vct
  • 73
  • 1
  • 10
1 2 3
23
24