Displaying 20 results from an estimated 10000 matches similar to: "how to pass additional parameters to a function called in tapply?"
2008 Mar 05
5
nls: different results if applied to normal or linearized data
Dear all,
I did a non-linear least square model fit
y ~ a * x^b
(a) > nls(y ~ a * x^b, start=list(a=1,b=1))
to obtain the coefficients a & b.
I did the same with the linearized formula, including a linear model
log(y) ~ log(a) + b * log(x)
(b) > nls(log10(y) ~ log10(a) + b*log10(x), start=list(a=1,b=1))
(c) > lm(log10(y) ~ log10(x))
I expected coefficient b to be identical
2008 Sep 23
0
additional parameters in function called by tapply
Der R-Gurus,
first apologies if this is a FAQ, but I due to lack of R-knowledge and terminology I wasn't able to find it.
I have the following problem in aggregating results of a model calculation:
The results are yearly values of several parameters with several hierarchical spatial factors taken from a database as a data frame with the following structure
value | year | spatial1 | spatial2
2005 Mar 21
2
X11 Fonts sizes
In postscript graphs (pointsize = 10, different sizes in graph adjusted via
cex) I would like to use different font sizes but get the following warning
message:
Warning messages:
1: X11 used font size 8 when 9 was requested
2: X11 used font size 8 when 7 was requested
3: X11 used font size 8 when 5 was requested
This is probably not a R but a X11 problem, nevertheless I would be most
2005 Aug 19
2
FFT, frequs, magnitudes, phases
Hi,
I'm in dire need of a fast fourier transformation for me stupid biologist,
i.e. I have a heartbeat signal and would like to decompose it into pure sin
waves, getting three vectors, one containing the frequencies of the sin
waves, one the magnitudes and one the phases (that's what I get from my data
acquisition software's FFT function).
I'd be very much obliged, if someone
2004 May 13
2
tapply & hist
I'm learning how to use tapply.
Now I'm having a go at the following code in which dati contains almost 600
lines, Pot - numeric - are the capacities of power plants and SGruppo - text
- the corresponding six technologies ("CCC", "CIC","TGC", "CSC","CPC", "TE").
.....................................................
2007 Nov 06
1
A suggestion for an amendment to tapply
Dear R-developers,
when tapply() is invoked on factors that have empty levels, it returns
NA. This behaviour is in accord with the tapply documentation, and is
reasonable in many cases. However, when FUN is sum, it would also
seem reasonable to return 0 instead of NA, because "the sum of an
empty set is zero, by definition."
I'd like to raise a discussion of the possibility of an
2010 Feb 02
3
tapply for function taking of >1 argument?
I'm sure I can put this together from the various 'apply's and split, but I
wonder if anyone has a quick incantation:
E.g. I can do tapply( data, groups, mean)
but how can I do something like: tapply( list(data,weights), groups,
weighted.mean ) ?
(or: mapply is to sapply as ? is to tapply )
Thanks for your help.
--
View this message in context:
2012 Sep 03
1
Scatter plot from tapply output, labels of data
Hei,
i am trying to plot the means of two variables (d13C and d15N), by 2
grouping factors (Species and Year) that i obtained by the function tapply.
I would like to plot with different colours according to the Year and show
the "Species" as data labels.
My data looks like this:
Species d13C d13N Year
"Species1" 14,4 11.5 2009
"Species2"
2008 Nov 14
1
# values used in a function in tapply
Hello,
I am using tapply to pull out data by the day of week and then perform
functions (e.g. mean). I would like to have the number of values used for
the calcuation for the functions, sorted by each day of week. A number of
entries in any given column are NAs.
I have tried the following code and simple variants with no luck.
for (i in 1:length(a[1,])){
x<-tapply(a[,i],a[,1],mean,
2007 Jun 18
1
getting tapply() to work across multiple columns
I have the following data.frame:
index <- c("a","a","b","b","b")
alpha <- c(1,2,3,4,5)
beta <- c(2,3,4,5,6)
table <-data.frame(index,alpha,beta)
I'm now interested in getting means of alpha and beta for each of the
index values and do a tapply() for each of the columns, e.g.
means.alpha <- tapply(table$alpha, index,mean)
2008 Sep 28
2
using tapply on a data frame in a function
Hello,
I'm trying to use tapply to find group means in a function. It works
outside of a function, but I get the error message from the following code:
"Error in tapply(index, cluster, mean) : arguments must have same length."
Any suggestions? Thanks.
eric
d <- data.frame(cbind(cluster=1:2, value1=1:10, value2=11:20))
d
FindClusterTraits <- function(framename, index){
2017 Jan 27
1
RFC: tapply(*, ..., init.value = NA)
The "no factor combination" case is distinguishable by 'tapply' with simplify=FALSE.
> D2 <- data.frame(n = gl(3,4), L = gl(6,2, labels=LETTERS[1:6]), N=3)
> D2 <- D2[-c(1,5), ]
> DN <- D2; DN[1,"N"] <- NA
> with(DN, tapply(N, list(n,L), FUN=sum, simplify=FALSE))
A B C D E F
1 NA 6 NULL NULL NULL NULL
2 NULL NULL 3 6
2004 Mar 15
2
Bug in tapply with factors containing NAs (PR#6672)
Full_Name: George Leigh
Version: 1.8.1
OS: Windows 2000
Submission from: (NULL) (203.25.1.208)
The following example gives the correct answer when the first argument of tapply
is a numeric vector, but an incorrect answer when it is a factor. If the
function used by tapply is "length", the type and contents of the first argument
should make no difference, provided it has the same
2009 Dec 01
1
Remark on tapply().
Consider the following:
> set.seed(42)
> ff <- factor(sample(c(1,3,5),42,TRUE),levels=1:5)
> x <- runif(42)
> tapply(x,ff,sum)
1 2 3 4 5
3.675436 NA 7.519675 NA 9.094210
I got bitten by those NAs in the result of tapply(). Effectively
one is summing over the empty set, and consequently (according to what
I learned as a child)
2011 Mar 15
1
Questions on dividing lists and tapply
Hello R community,
I have two questions about using R.
The first is about dividing each element of a list with another similar
sized list. So, if the first list has two elements and so does the second,
then the result should also be a list with two elements.
For example, the inputs are:
list(matrix(1:6,ncol=2),matrix(1:6,ncol=2))->l1
l2<-list(1:3,2)
I want to get a list, l3 with the
2009 Apr 13
3
tapply output as a dataframe
i use tapply and by often, but i always end up banging my head against
the wall with the output.
is there a simpler way to convert the output of the following tapply to
a dataframe or matrix than what i have here:
# setup data for tapply
dt = data.frame(bucket=rep(1:4,25),val=rnorm(100))
fn = function(x) {
ret =
c(unname(quantile(x,probs=seq(.25,.75,.25),na.rm=T)),mean(x,na.rm=T))
}
a =
2008 Sep 09
2
exporting tapply objects to csv-files
Dear Everyone,
I try to create a cvs-file with different results form the table function.
Imagine a data-frame with two vectors a and b where b is of the class factor.
I use the tapply function to count a for the different values of b.
tapply(a,b,table)
and I use the table function to have a look of the frequencies as a total
table(a)
I would like to put both results together in one txt or
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
2008 Jul 08
3
extracting index list when using tapply()
Hello,
The quick version of my question is how can I extract a matrix instead of
a vector using tapply()? I would like to be able to access both the results
of tapply() and also the index variables.
In case further explanation would help: I am analyzing a large (3million
rows x 9 columns) spatial/temporal dataset and am attempting to calculate
the number of unique years containing any data
2005 Aug 08
1
tapply huge speed difference if X has names
Hi all,
Apologies if this has been raised before ... R's tapply is very fast, but if
X has names in this example, there seems to be a huge slow down: under 1
second compared to 151 seconds. The following timings are repeatable and
are timed properly on a single user machine :
> X = 1:100000
> names(X) = X
> system.time(fast<<-tapply(as.vector(X), rep(1:10000,each=10), mean))