Hi Folks Iam a new user of R and I have a question . Hopefully anyone help me in that issue I have that dataset as following Sample Population Species Tissue R G B 1 Bari1_062-1 Bari1 ret seed 94.52303 80.70346 67.91760 2 Bari1_062-2 Bari1 ret seed 98.27683 82.68690 68.55485 3 Bari1_062-3 Bari1 ret seed 100.53170 86.56411 73.27528 4 Bari1_062-4 Bari1 ret seed 96.65940 84.09197 72.05974 5 Bari1_062-5 Bari1 ret seed 117.62474 98.49354 84.65656 6 Bari1_063-1 Bari1 ret seed 144.39547 113.76170 99.95633 and I have 20 populations as following [1] Bari1 Bari2 Bari3 Besev Cermik Cudi Derici Destek Egil [10] Gunasan Kalkan Karabace Kayatepe Kesentas Ortanca Oyali Cultivated Sarikaya [19] Savur Sirnak I need to calculate mean and variance of each population using column [R] using for-loop Thanks [[alternative HTML version deleted]]
Have you read the tutorial that comes with the R distribution? This is a very basic database calculation that you will encounter (or some slight variation of it) over and over. The solution is a few lines of code, and someone may write it out for you, but if no one does You have 20 populations, so you will have 20 iterations in your for loop. For each one, you will need a unique identifier that points to the rows of ?R? associated with that population. You?ll calculate a mean and variance 20 times, and will need a data object to store those calculations. Look in the tutorial for syntax for identifying subsets of your data frame.> On Nov 5, 2014, at 5:41 AM, Noha Osman <nmo_138 at usc.edu> wrote: > > Hi Folks > > Iam a new user of R and I have a question . Hopefully anyone help me in that issue > > > I have that dataset as following > > Sample Population Species Tissue R G B > 1 Bari1_062-1 Bari1 ret seed 94.52303 80.70346 67.91760 > 2 Bari1_062-2 Bari1 ret seed 98.27683 82.68690 68.55485 > 3 Bari1_062-3 Bari1 ret seed 100.53170 86.56411 73.27528 > 4 Bari1_062-4 Bari1 ret seed 96.65940 84.09197 72.05974 > 5 Bari1_062-5 Bari1 ret seed 117.62474 98.49354 84.65656 > 6 Bari1_063-1 Bari1 ret seed 144.39547 113.76170 99.95633 > > and I have 20 populations as following > > [1] Bari1 Bari2 Bari3 Besev Cermik Cudi Derici Destek Egil > [10] Gunasan Kalkan Karabace Kayatepe Kesentas Ortanca Oyali Cultivated Sarikaya > [19] Savur Sirnak > > I need to calculate mean and variance of each population using column [R] using for-loop > > > Thanks > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.Don McKenzie Research Ecologist Pacific Wildland Fire Sciences Lab US Forest Service Affiliate Faculty School of Environmental and Forest Sciences University of Washington dmck at uw.edu
On 11/5/2014 5:41 AM, Noha Osman wrote:> Hi Folks > > Iam a new user of R and I have a question . Hopefully anyone help me in that issue > > > I have that dataset as following > > Sample Population Species Tissue R G B > 1 Bari1_062-1 Bari1 ret seed 94.52303 80.70346 67.91760 > 2 Bari1_062-2 Bari1 ret seed 98.27683 82.68690 68.55485 > 3 Bari1_062-3 Bari1 ret seed 100.53170 86.56411 73.27528 > 4 Bari1_062-4 Bari1 ret seed 96.65940 84.09197 72.05974 > 5 Bari1_062-5 Bari1 ret seed 117.62474 98.49354 84.65656 > 6 Bari1_063-1 Bari1 ret seed 144.39547 113.76170 99.95633 > > and I have 20 populations as following > > [1] Bari1 Bari2 Bari3 Besev Cermik Cudi Derici Destek Egil > [10] Gunasan Kalkan Karabace Kayatepe Kesentas Ortanca Oyali Cultivated Sarikaya > [19] Savur Sirnak > > I need to calculate mean and variance of each population using column [R] using for-loop > > > Thanks >You don't want to use loops here, but rather some vectorized function. One possibility is some thing like the following: with(your_data_frame,aggregate(R,list(Population), mean)) with(your_data_frame,aggregate(R,list(Population), var)) hope this is helpful, Dan Daniel Nordlund Bothell, WA USA
On 05-11-2014, at 14:41, Noha Osman <nmo_138 at usc.edu> wrote:> Hi Folks > > Iam a new user of R and I have a question . Hopefully anyone help me in that issue > > > I have that dataset as following > > Sample Population Species Tissue R G B > 1 Bari1_062-1 Bari1 ret seed 94.52303 80.70346 67.91760 > 2 Bari1_062-2 Bari1 ret seed 98.27683 82.68690 68.55485 > 3 Bari1_062-3 Bari1 ret seed 100.53170 86.56411 73.27528 > 4 Bari1_062-4 Bari1 ret seed 96.65940 84.09197 72.05974 > 5 Bari1_062-5 Bari1 ret seed 117.62474 98.49354 84.65656 > 6 Bari1_063-1 Bari1 ret seed 144.39547 113.76170 99.95633 > > and I have 20 populations as following > > [1] Bari1 Bari2 Bari3 Besev Cermik Cudi Derici Destek Egil > [10] Gunasan Kalkan Karabace Kayatepe Kesentas Ortanca Oyali Cultivated Sarikaya > [19] Savur Sirnak > > I need to calculate mean and variance of each population using column [R] using for-loopIf I?m correct you asked an almost identical question Stackoverflow (http://stackoverflow.com/questions/26742023/how-can-i-use-loops-in-r). You got all the answers you need. Berend