All Questions

839
votes
9answers
328383 views

Grouping functions (tapply, by, aggregate) and the *apply family

Whenever I want to do something "map"py in R, I usually try to use a function in the apply family. However, I've never quite understood the differences between them -- how {sapply, lapply, etc.} app...
13
votes
4answers
10576 views

Multiple functions in a single tapply or aggregate statement

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 to c...
2
votes
7answers
2457 views

How do I do a conditional sum which only looks between certain date criteria

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-01-...
3
votes
3answers
906 views

How to add tapply results to an existing data frame

I would like to add tapply results to the original data frame as a new column. Here is my data frame: dat <- read.table(text = " category birds wolfs snakes yes ...
11
votes
3answers
23327 views

sum multiple columns by group with tapply

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 searched...
1
votes
3answers
674 views

Computing pairwise Hamming distance between all rows of two integer matrices/data frames

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 e107...
4
votes
3answers
825 views

R function which.max with tapply

I am trying to make a data frame with the maximum over records by a factor. I would like a data frame with 4 rows (one for each G) with the max for X in that group and the corresponding Y value. I kno...
7
votes
4answers
225 views

How to assign a counter to a specific subset of a data.frame which is defined by a factor combination?

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 <-da...
-7
votes
1answers
646 views

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 v1...
5
votes
1answers
623 views

What is the difference between the functions tapply and ave?

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 not ...

Previous Next