Posts

RPubs - Sample (), Simulation, and Apply Functions

Image
  Sample(), Simulation, and the Apply Function Nirmal Ghimire 2/27/2021 This tutorial is about using a few Simple R functions using the ‘sampling’ command. 1. sample function() 2. for loops 3. apply () function when working with R there are various reasons why we want R to do some task repeatedly,like running through every row in the data set and performing some calculations. Or may be, we want to run a simulation that requires repeated draw of samples from some population or run some sort of iterated experiment in order to estimate a statistic– for example, the sample mean. Let’s Look at the sample() command. At first, I am going to define a vector named ‘states’ and give some states’ name to be stored in the vector. Or the vector “state” has three character elements, i.e., three U.S. states. states<-c( "Florida" , "Georgia" , "Alabama" ) states [1] "Florida" "Georgia" "Alabama" Simulating the Sample Once I created the vec