Displaying 20 results from an estimated 3000 matches similar to: "Any way to apply TWO functions with tapply()?"
2010 Jul 16
2
aggregate(...) with multiple functions
hi all - i'm just wondering what sort of code people write to
essentially performa an aggregate call, but with different functions
being applied to the various columns.
for example, if i have a data frame x and would like to marginalize by
a factor f for the rows, but apply mean() to col1 and median() to
col2.
if i wanted to apply mean() to both columns, i would call:
aggregate(x, list(f),
2011 Nov 14
3
max & min values within dataframe
dear R-team
I need to find the min, max values for each patient from dataset and keep
the output of it as a dataframe with the following columns
- Patient nr
- Region (remains same per patient)
- Min score
- Max score
Patient Region Score Time
1 1 X 19 28
2 1 X 20 126
3 1 X 22 100
4 1 X 25 191
5 2 Y 12 1
2010 Jan 18
2
column selection for aggregate()
Hi everybody!
I'm working on R today so I have a lot of questions (you may have
noticed that it's the 3rd email today). I'm new on R, so please excuse
the "spam"!
I have a dataset "ssfa" with many rows and the column names are:
> names(ssfa)
[1] "SPECSHOR" "BONE" "TO_POS" "MEASUREM" "FACETTE"
2007 Jul 16
5
formula(CO2)
The formula attribute of the builtin CO2 dataset seems a bit strange:
> formula(CO2)
Plant ~ Type + Treatment + conc + uptake
What is one supposed to do with that? Certainly its not suitable for
input to lm and none of the examples in ?CO2 use the above.
2007 Jan 01
3
Wish list
This is my 2007 New Year wishlist for R features:
1. Matrix Multiplication
Enhance matrix multiplication to work with multidimensional
arrays such that the last dimension of the first multiplicand
must equal the first dimension of the second. See:
https://www.stat.math.ethz.ch/pipermail/r-devel/2006-July/038497.html
2. Grid
- logical-valued function as first arg of grid.edit
-
2011 Feb 25
4
means, SD's and tapply
I'm trying to use tapply to output means and SD or SE for my data but
seem to be limited by how many times I can subset it. Here's a snippet
of my data
> stems353[1:10,]
Time DataSource Plot Elevation Aspect Slope Type Species
SizeClass Stems
1 Modern Cameron 70F221 1730 ESE 20 Conifer ABCO
Class1 3
2 Modern Cameron 70F221 1730
2006 Mar 15
1
filtering in aggregate
Hello all,
I have a data frame with year, month, species, fishing gear and catch
(Y, M, S, F, C) and I want the sum of C by Y for species "A" and fishing
gear "trawl".
I tried things like aggregate(C[S=="A" & F=="trawl"], list (Year =
Y[S=="A" & F=="trawl"]), fun=sum), but it didn't worked.
To overcome this problem I did
2013 Jan 17
3
how to use "..."
Dear users,
I'm trying to learn how to use the "...".
I have written a function (simplified here) that uses doBy::summaryBy():
# 'dat' is a data.frame from which the aggregation is computed
# 'vec_cat' is a integer vector defining which columns of the data.frame
should be use on the right side of the formula
# 'stat_fun' is the function that will be run to
2007 Jun 04
3
test for nested factors
Is there a conventional way to test for nested factors? I.e., if 'a'
and 'b' are lists of same-length factors, does each level specified by
'a' correspond to exactly one level specified by 'b'?
The function below seems to suffice, but I'd be happy to know of a more
succinct solution, if it already exists.
Thanks,
Tim.
---
"%nested.in%" <-
2007 Aug 31
3
data frame row manipulation
Hello,
struggling with the very basic needs... :( any help appreciated.
#using the package doBY
#who drinks how much beer per day and therefor cannot calculate rowise
maxvals
evaluation=data.frame(date=c(1,2,3,4,5,6,7,8,9),
name=c("Michael","Steve","Bob",
"Michael","Steve","Bob","Michael","Steve","Bob"),
2010 Dec 17
2
newbie question on str output
Hi!
Here is some output from an str command:
> str(CO2)
Classes ‘nfnGroupedData’, ‘nfGroupedData’, ‘groupedData’ and
'data.frame': 84 obs. of 5 variables:
$ Plant : Ord.factor w/ 12 levels "Qn1"<"Qn2"<"Qn3"<..: 1 1 1 1 1 1 1 2
2 2 ...
$ Type : Factor w/ 2 levels "Quebec","Mississippi": 1 1 1 1 1 1 1 1 1 1
...
$
2009 Apr 06
5
SUM,COUNT,AVG
Hi,
I ve been searching a lot in internet..but I can t find a solution
Attached, you find a file.
I need for each (Materiale, tpdv, UM) to find sum,avg and count
My idea was to aggregate for the 3 parameters ..but I don t know how to get
the numeric value (SUM,COUNT,AVG) I need.
Can you help me?
thank you
http://www.nabble.com/file/p22905322/ordini2008_ex.txt ordini2008_ex.txt
--
View this
2010 Feb 08
1
Follow-up Question: data frames; matching/merging
Wow.. thanks for the deluge of responses!
Aggregate seems like the way to go here.
But, suppose that instead of integers in column V2, I actually have
dates (and instead of keeping the minimum integer, I want to keep the
earliest date):
> df =
2009 Aug 05
2
Counting things
I've completed an experiment and want to summarize the results.
There are two things I like to create.
1) A simple count of things from the data.frame with predictions
1a) Number of predictions with probability greater than x
1b) Number of predictions with probability greater than x that are
really true
In SQL, this would be,
"Select count(predictions) from
2012 Apr 02
2
summaryBy: transformed variable on RHS of formula?
Hi Folks,
I'm trying to cut my data inside the summaryBy function. Perhaps
formulas don't work that way? I'd like to avoid adding another column
if possible, but if I have to, I have to. Any ideas?
Thanks,
Allie
require(doBy)
df = dataframe(a <- rnorm(100), b <-rnorm(100))
summaryBy(a ~ cut(b,c(-100,-1,1,100)), data=df) # preferred
solution, but it throws an
2010 Mar 17
2
Using nrow with summaryBy
Hello Everyone-
I'm calculating summary statistics on a dataset (~4000 records,
observations are not uniformly distributed) using summaryBy and trying
to add a column with the number of observations to the output as well.
What occurs to me is to use nrow(), but this doesn't appear to be working
I'm able to replicate the same results with an example from the
summaryBy docs:
2008 Aug 07
6
multiple tapply
Hi folk,
I tried this and it works just perfectly
tapply(iris[,1],iris[5],mean)
but, how to obtain a single table from multiple variables?
In tapply x is an atomic object so this code doesn't work
tapply(iris[,1:4],iris[5],mean)
Thanx and great summer holidays
Gianandrea
--
View this message in context: http://www.nabble.com/multiple-tapply-tp18868063p18868063.html
Sent from the R help
2009 Mar 15
2
xyplot of a specific ID number
Dear R list members,
I have a question regarding xyplot. I managed to make a xyplot of all the
IDs by using the syntax below:
xyplot(PA ~ CRPC + CRPT | ID, data = redinteract)
Now, I'd like to make a graph of a specific ID number (e.g., only ID number
301). I thought I could use "subset", but it seems to be not working.
Could anyone let me know how I can make a graph of a
2011 Jan 17
2
Using summaryBy with weighted data
Dear Soren and R users:
I am trying to use the summaryBy function with weights. Is this possible? An example that illustrates what I am trying to do follows:
library(doBy)
## make up some data
response = rnorm(100)
group = c(rep(1,20), rep(2,20), rep(3,20), rep(4,20), rep(5,20))
weights = runif(100, 0, 1)
mydata = data.frame(response,group,weights)
## run summaryBy without weights:
2010 Jan 04
4
function in aggregate applied to specific columns only
I want to use aggregate with the mean function on specific columns
gender <- factor(c("m", "m", "f", "f", "m"))
student <- c(0001, 0002, 0003, 0003, 0001)
score <- c(50, 60, 70, 65, 60)
basicSub <- data.frame(student, gender, score)
basicSubMean <- aggregate(basicSub, by=list(basicSub$student), FUN=mean, na.rm=TRUE)
This