Hi everyone, I have dataset which I make a sample of it couple of times and each time I get the mean and standard deviation of each row for each sample. I have a function for that, which takes the name of the file and number of times to sample and then returns the mean and standard deviation for each row in each sample.
Sample=function(name, n){ res=replicate(n,name[,sample(colnames(name),n)],simplify=FALSE) Means=do.call(rbind,lapply(res,function(x) rowMeans(x))) rownames(Means)=paste('sample',1:n,sep="") Gmean=colMeans(Means) STDs=do.call(rbind,lapply(res,function(x) rowSds(x))) rownames(STDs)=paste('sample',1:5,sep="") Gsd=sd(STDs) return(Gmean,Gsd)} I then need to use the mean and standard deviation from each row to calculate the Power for 2 sample means. here is the function I use to do it: Power=function(alfa,m1,m2,s1,s2,n1,n2){ up=abs(m1-m2) down=sqrt(((s1^2)/(n1))+((s2^2)/(n2))) z=(-1)*(qnorm(1-(alfa/2))) fi=z+(up/down) pow=pnorm(fi) return(pow)} then I need to call the Power function: Power(.05,57,mi,33,si,200,n) the alfa,m1,s1 and n1 values are constant but the m2,s2 and n2 values are changing. n2 is the n used in sample function(which I could input manually) m2 should be the grand mean for each row s2 is the grand standard deviation for each row example:this is a sample output for "sample" function: $Gmean s1 s2 s3 s4 0.08 0.20 0.12 0.20 $Gsd s1 s2 s3 s4 0.2449490 0.2156741 0.2449490 0.2156741 my problem is how can I put the corresponding means and standard devotions together in the power function?I used a for loop, but the problem is getting the s1...s4 from Gmean and Gsd Thanks for your help -- View this message in context: http://www.nabble.com/function-help-tp20035949p20035949.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.