similar to: apply mean function to a subset of data

Displaying 20 results from an estimated 1000 matches similar to: "apply mean function to a subset of data"

2016 Apr 03
1
apply mean function to a subset of data
Here are several ways to get there, but your original loop is fine once it is corrected: > for (i in 1:2) smean[i] <- mean(toy$diam[toy$group==i][1:nsel[i]]) > smean [1] 0.271489 1.117015 Using sapply() to hide the loop: > smean <- sapply(1:2, function(x) mean((toy$diam[toy$group==x])[1:nsel[x]])) > smean [1] 0.271489 1.117015 Or use head() > smean <- sapply(1:2,
2016 Apr 02
0
apply mean function to a subset of data
Hi Pedro, This may not be much of an improvement, but it was a challenge. selvec<-as.vector(matrix(c(nsel,unlist(by(toy$diam,toy$group,length))-nsel), ncol=2,byrow=TRUE)) TFvec<-rep(c(TRUE,FALSE),length.out=length(selvec)) toynsel<-rep(TFvec,selvec) by(toy[toynsel,]$diam,toy[toynsel,]$group,mean) Jim On 4/3/16, Pedro Mardones <mardones.p at gmail.com> wrote: > Dear all; >
2009 Nov 16
2
Conditional statement
Dear useRs, I wrote a function that simulates a stochastic model in discrete time. The problem is that the stochastic parameters should not be negative and sometimes they happen to be. How can I conditionate it to when it draws a negative number, it transforms into zero in that time step? Here is the function: stochastic_prost <- function(Fmean, Fsd, Smean, Ssd, f, s, n, time, out=FALSE,
2004 Dec 03
1
Difficulty implementing "scales" in a lattice plot
Hello all, I am rather new to lattice and have a simple question regarding formatting text labels on the axes. I have looked through my own archive on lattice notes, searched and examined 30 or so hits on Dr. Baron's search site, looked through my MASS book, my Data Analysis and Graphics Using R book, R news articles, and I have in my hand the lattice package instructions and have read and
2016 Jun 24
2
UPS is not turned off in slave-only configuration?
On Mittwoch, 22. Juni 2016 17:50, Roger Price wrote: On Wed, 22 Jun 2016, Andr? H?nsel wrote: > > Now, what I see is that when the UPS feeding server-1 goes LB, > > server-1 is indeed shut down, but it seems that the UPS is never switched off. > > > > This is a problem because when power is restored after shutdown, but > > before the battery runs out (with no
2002 Oct 31
7
Symbols for male/female
Dear all, I would like to use the biological symbols for male and female as plotting symbols in a scatterplot (ideally filled and non-filled). R does not seem to have these symbols using pch= in plot() nor are they implemented via expression() or at least I did not find them. I found that the symbols are e.g. available in the wasysym and the marvosym package in LaTeX. I have coded two very rough
2002 Oct 31
7
Symbols for male/female
Dear all, I would like to use the biological symbols for male and female as plotting symbols in a scatterplot (ideally filled and non-filled). R does not seem to have these symbols using pch= in plot() nor are they implemented via expression() or at least I did not find them. I found that the symbols are e.g. available in the wasysym and the marvosym package in LaTeX. I have coded two very rough
2006 Feb 08
1
Simple optim - question
Hello, I want to find the parameters mu and sigma that minimize the following function. It's important, that mu and sigma are strictly positive. ----------------- optimiere = function(fmean,smean,d,x,mu,sigma) { merk = c() for (i in 1:length(d)) merk=c(merk,1/(d[i]^2)*(d[i]-1/(fmean*(1-plnorm(x[i],mu,sigma))))^2) return(sum(merk)) } ----------------- To do that I'm using the nlm
2006 Aug 09
1
nested ANOVA using lme
I have an ANOVA model with 2 factors "Environment" and "Site", "Diameter" is the response variable. Site should be nested within Environment. Site is also a random factor while Environment is fixed. I can do this analysis using the "aov" function by using these commands: >model<-aov(Diam~Env+Error(Env%in%Site),data=environ) >summary(model)
2009 Oct 23
3
opposite estimates from zeroinfl() and hurdle()
Dear all, A question related to the following has been asked on R-help before, but I could not find any answer to it. Input will be much appreciated. I got an unexpected sign of the "slope" parameter associated with a covariate (diam) using zeroinfl(). It led me to compare the estimates given by zeroinfl() and hurdle(): The (significant) negative estimate here is surprising, given
2010 Oct 03
1
scatterplot error message
Hi All. I am a new R user. Trying to do scatterplot. Not sure how to resolve this error message A<-subset (ErablesGatineau, station=="A") > B<-subset (ErablesGatineau, station=="B") > > plot(diam ~ biom) > abline(lm(diam ~ biom), col = "red") > > goodcases <- !(is.na(diam) | is.na(biom)) > lines(lowess(diam[goodcases] ~
2007 Jun 14
4
question about formula for lm
Dear all; Is there any way to make this to work?: .x<-rnorm(50,10,3) .y<-.x+rnorm(50,0,1) X<-data.frame(.x,.y) colnames(X)<-c("Xvar","Yvar") Ytext<-"Yvar" lm(Ytext~Xvar,data=X) # doesn't run lm(Yvar~Xvar,data=X) # does run The main idea is to use Ytext as input in a function, so you just type "Yvar" and the model should fit....
2002 Sep 30
2
Decompose numerical factor into orthog. poly parts
Consider the following analysis of a class experiment done as a Latin Square: > spinner <- gl(4,4,16,label=c("Murray","Angela","Shasha","Stephen")) > order <- gl(4,1,16) > treat <- scan() 1: 1 2 4 3 5: 4 3 1 2 9: 3 4 2 1 13: 2 1 3 4 17: Read 16 items > coin <-
2007 May 11
3
how to get column/row info from a dist object?
Dear R users; Is it possible to get the row and column number of a particular entry in a dist object? Let's say that I want to find the position of the value 1.1837 (the last entry on the dist object below), that is [6,3]. Can I get those values without transforming the object to a matrix?, i.e. working with the dist object only. 1 2 3 2 0.23935864
2006 Jan 26
1
[R-SIG-Mac] Hist for different levels of a factor
The list of your interest is R-help not R-sig-mac stefano Il giorno 26/gen/06, alle ore 01:20, Sylvain Charlat ha scritto: > Hi, > > Is there any simple way to get histogram for different levels of > factor? > > Say you have the following data set: > > Island Sp.diam > Moorea 1.21 > Moorea 1.27 > Moorea 1.28 > Moorea 1.22 > Moorea 1.28 > Rurutu
2011 Sep 20
5
help in interpreting paired t-test
Dear all; A very basic question. I have the following data: ************************************************************************************ A <- 1/1000*c(347,328,129,122,18,57,105,188,57,257,53,108,336,163, 62,112,334,249,45,244,211,175,174,26,375,346,153,32, 89,32,358,202,123,131,88,36,30,67,96,135,219,122, 89,117,86,169,179,54,48,40,54,568,664,277,91,290,
2006 Jan 25
1
How to use rfm.test ? (Package MarkedPointProcess)
I would like to compute the MC test (rfm.test) available in the package MarkedPointProcess (for the data BITOEK for example) in order to test the dependence between the marks and their locations. Why the syntax of rfm.test is false here? I have the message : ****************************** ML WARNING! Forbidden values! -- if there are too many warnings try narrower lower and upper bounds for the
2007 Apr 21
0
possible bug in xYplot and smean.cl.normal
I'm using R (2.4.1) and Hmisc (3.3-1), and I'd like to plot confidence intervals using xYplot and smean.cl.normal (or smean.cl.boot) from Hmisc. You can do that using the summarize() to produce a new data.frame and then plot with xYplot, or by specifying method=smean.cl.normal in the xYplot. Both produce very similar graphs in all trivial examples I've tried, but not in the attached
2009 Jan 18
2
don't print object attributes on screen
Dear all; I have a function written in R that returns as a list of values as output that has associated some user defined attributes to it. How can hide these attributes when printing the output on screen? I'm using R-2.8.1 on WinXP....it's like hiding the attr of the output from the scale function.... Thanks in advance PM
2009 Mar 14
4
persp plot + plotting grid lines
Dear all; Does anyone know how to add grid lines to a persp plot? I've tried using lines(trans3d..) but the lines of course are superimposed into the actual 3d surface and what I need is something like the plot shown in the following link: http://thermal.gg.utah.edu/tutorials/matlab/matlab_tutorial.html I'll appreciate any ideas Thanks PM