Database Reference
In-Depth Information
x=seq(1, 1000, by=2)
y=seq(2, 1000, by=2)
z=c(x,y)
length(z)
mean(x)
median(y)
sd(y)
max(x)
min(y)
sort(z)
summary(z)
The rep command is used for repeating values, shown as follows:
There are many other important data types in R like lists and data frames that are
used abundantly. This topic just introduces to the concept of R programming. In the
next section, we will implement Monte Carlo simulations using R programming.
When there is a lot of randomness in the inputs, it is very difficult to compute output
precisely, even though the output-input relation is simple and well established. In
such a case:
1. Generate randomly one possible outcome with one possible set of inputs.
2. Repeat it large number of times.
3. Take the average or summary statistic.
Let us work out a number of trivial and not so trivial problems to illustrate the useful-
ness of the approach.
Let us start with computing the value of pi. While nobody computes pi using this
method, it gives a fairly good view of how the Monte Carlo method works.
Search WWH ::




Custom Search