Tuesday, July 7, 2015

R Programming Examples- 2

Posted by   on

R codes are shown live.
 Just type the codes & put Enter on your Key-board.

Code Execution
chose(12,8) Combination of 8 objects out of 12. 12C3
gamma(5) Gives value of gamma function
?’+’ Arithmetic Operator help page.
factorial(9) 9!
exp(2.3) e2.3
2.7^2 2.72
sqrt(64) Square Root of 64
beta(2,3) Value of beta function with parameters 2 & 3.
round(2.3) Rounds 2.3. See more examples in the examples section below.
round(2.476,2) Rounds the value up to 2 digits.
pi Gives value
abs(-2) Gives absolute value
b=3 Assigns b as 3
class(b) Type of object of b.
class(log) To test the type of log.
Note: It can be done for testing any function or value.
Also note, log is a function while ‘b’ is a numeric/value.
x=c(1,3,4,5) Makes a vector with the values respectively.
x=scan() Another option to make a vector.
Note: after pressing Enter, input values as many as you need. Then again push Enter to stop entering values. See example below.
rm(x) Deletes a command
y=seq(1,3,.1) Gives values 1 through 3 with difference .1.
x=1:100 Does almost same but applicable for integers only as you cannot define difference.
rep(1,10) Gives 1 10 times.
floor(2.3) Transforms to nearest lower integer.
floor(2.9) Transforms to nearest lower integer.
Note : Unlike ‘round’ it goes below rather than above.
ceiling(2.3) Nearest upper Integer.
ceiling(2.3) Nearest upper Integer.
round(2.3) Rounding the value
round(2.6) Rounding the value




No comments:
Write comments

Hey, we've a very popular astronomy portal in Bangla language. If You know Bangla, You'll like it - sky.bishwo.com
Join Our Newsletter