tapply Questions

5

Solved

Is it possible to include two functions within a single tapply or aggregate statement? Below I use two tapply statements and two aggregate statements: one for mean and one for SD. I would prefer t...
Cribbage asked 5/3, 2013 at 3:2

2

Solved

I would like to draw a plot with percentage labels per x-axis group. This works fine without empty groups: # library library(ggplot2) library(reshape2) # example data from reshape2 str(tips) #>...
Lyonnaise asked 2/4, 2022 at 15:54

1

I have a dataframe similar to this one ID <- c(1,1,1,1,1,2,2,2,2,2,3,3,3,3,3) p1 <- c(21000, 23400, 26800, 2345, 23464, 34563, 456433, 56543, 34543,3524, 353, 3432, 4542, 6343, 4534 ) ...
Hutch asked 20/1, 2017 at 10:11

3

Solved

I have two data frames, df1 with reference data and df2 with new data. For each row in df2, I need to find the best (and the second best) matching row to df1 in terms of hamming distance. I used e...
Sleep asked 20/6, 2016 at 1:9

2

Solved

I would like to apply grep() in R, but I am not really good in lapply(). I understand that lapply is able to take a list, apply function to each members and output a list. For instance, let x be a ...
Kiowa asked 14/3, 2016 at 5:36

2

Solved

I have the following df: group = rep(seq(1,3),30) variable = runif(90, 5.0, 7.5) df = data.frame(group,variable) I need to i) Define quantile by groups, ii) Assign each person to her quantile wi...
Constrict asked 17/2, 2016 at 10:24

2

Solved

How do I combine the tapply command with 'not in' logic? Objective: Obtain the median sepal length for each species. tapply(iris$Sepal.Length, iris$Species, median) Constraint: Remove entries ...
Unbodied asked 11/5, 2015 at 21:31

3

Solved

There seems to be general agreement that the l in "lapply" stands for list, the s in "sapply" stands for simplify and the r in "rapply" stands for recursively. But I could not find anything on the ...
Clangor asked 21/4, 2015 at 23:33

2

Solved

I´d like to calculate mean and sd from a dataframe with one column for the parameter and one column for a group identifier. How can I calculate them when using tapply? I could use sd(v1, group, na....
Blus asked 5/1, 2013 at 14:10

3

Solved

I have a matrix, data.mat, that looks like: A B C D E 45 43 45 65 23 12 45 56 NA NA 13 4 34 12 NA I am trying to turn this into a list of lists, where each row is one list within a bigger li...
Dimorph asked 11/9, 2014 at 0:18

7

Solved

Say I have data that looks like date, user, items_bought, event_number 2013-01-01, x, 2, 1 2013-01-02, x, 1, 2 2013-01-03, x, 0, 3 2013-01-04, x, 0, 4 2013-01-04, x, 1, 5 2013-01-04, x, 2, 6 2013-...
Rau asked 3/6, 2014 at 16:23

1

Solved

I can't wrap my mind around the ave function. I read the help and searched the net but I still cannot understand what it does. I understand it applies some function on a subset of observation but n...
Genuine asked 9/3, 2014 at 22:47

2

Solved

I have a dataset that contains the feeding data of 3 animals, consisting of the animals' tag ids (1,2,3), the type (A,B) and amount (kg) of feed given at each 'meal': Animal FeedType Amount(kg) A...
Weimaraner asked 3/1, 2014 at 14:21

2

Solved

I am trying to find the summary statistics for different factor levels. data.frame(apply(final_data[Company=="BPO",c(66:84)],2,summary)) Now I have different values for company - i can repeat ...
Kissee asked 19/12, 2013 at 18:29

3

Solved

I wanted to sum individual columns by group and my first thought was to use tapply. However, I cannot get tapply to work. Can tapply be used to sum multiple columns? If not, why not? I have search...
Boiler asked 27/7, 2013 at 22:45

2

Solved

I have the following data: a <- c(1,1,1,1,2,2,2,2) b <- c(2,4,6,8,2,3,4,1) c <- factor(c("A","B","A","B","A","B","A","B")) df <- data.frame( sp=a, length=b, method=c) I can use th...
Strophanthin asked 21/5, 2013 at 7:9

2

Does the by function make a list that grows one element at a time? I need to process a data frame with about 4M observations grouped by a factor column. The situation is similar to the example bel...
Frailty asked 4/12, 2012 at 14:48

4

Solved

My question is: I have a data frame with some factor variables. I now want to assign a new vector to this data frame, which creates an index for each subset of those factor variables. data <-d...
Datestamp asked 25/10, 2012 at 15:10

1

I've learned R by toying, and I'm starting to think that I'm abusing the tapply function. Are there better ways to do some of the following actions? Granted, they work, but as they get more complex...
Amusement asked 16/9, 2009 at 17:32
1

© 2022 - 2024 — McMap. All rights reserved.