Thursday, May 12, 2016

R Language - Mathematical Commands



abs(x) Takes the absolute value of x
log(x,base=y) Takes the logarithm of x with base y; if base is not specified, returns the natural logarithm
exp(x) Returns the exponential of x
sqrt(x) Returns the square root of x
factorial(x) Returns the factorial of x (x!)
choose(x,y)
Returns the number of possible combinations when drawing y elements at a time from x
possibilities

round(x,digits=2)

signif(x,digits=4)


cos(120)
R always works with angles in radians, not in degrees. Pay attention to this fact

So correct way to cos of 120 degrees is to write cos(120*pi/180)

The str() function gives you the type and structure of the object.

If you want to know only how long a vector is, you can simply use the
length() function,

Creating vectors
seq(from = 4.5, to = 2.5, by = -0.5)

The c() function stands for concatenate. It doesn’t create vectors — it combines them.

To repeat the vector c(0, 0, 7) three times, use this code:  rep(c(0, 0, 7), times = 3)

You also can repeat every value by specifying the argument each in place of times.

rep(1:3,length.out=7)  says repeat the vector till length is 7. The last repetition may be incomplete.

The bracket  [] represents a function that you can use to extract a value from that vector. You can get the fifth value of the vector numbers bygiving the command. 
numbers[5]





No comments:

Post a Comment