Friday, August 7, 2015

Programming with R: part-2

Posted by   on

Links to all courses
R Codes: part-2
Purpose Purpose
X = c(1,3,5) To make a vector with values 1, 3 & 5.
X= scan () Press enter. Then put values and again enter when all desired values are given.
X = seq (2,5,1) Values 2 thru 5 with interval 1.
Rm(x) To delete a command, say x, from memory
X = 1: 10 Assigning values 1 thru 10 to x.
Rep (1, 10) Output 1 ten times.
Floor (2.3) To make it 2
Floor(2.9) To make it 2.
That is, by using ‘floor’, you are going backwards i.e. to the previous numbers while rounding
Ceiling (2.3) To make it 3
Ceiling (2.9) To make it 3.
That is, by using ‘ceiling, you are going forward while rounding i.e. to the previous numbers while rounding
Round (2.3) Normal rounding
Round(2.9) Normal rounding
Trunc(2.3) Rounding and getting integer i.e. vanishing decimal
Trunc(2.9) Rounding and getting integer i.e. vanishing decimal
X = runif(10000, -1,1) To take a sample from uniform distribution over the interval (-1,1)
X= runif(10000,1,4) Generating normal distribution with mean 1 and variance 4.
Var(x) Variance of a distribution
Mean(x) Get mean
Sort(x) Arrange in ascending order
Sort(x, descending=F) Arrange in descending order
Sort(x,T) Arrange in descending order
X+1 If x is a vector, then x+1 command adds 1 to every value of the vector.
x-y Subtract corresponding elements of one vector from another when x & y are vectors. Otherwise just values.
x/y
X[3] 3rd value of a vector x. It’s applicable when a vector contains a lot of elements.
X[3] = 7 Convert 3rd value of a vector x into 7
x= c[1:10) A vector from elements 1 thru 10.
X[c(5,6,70}= 0 5th ,6th &7th equating to 0
X[5:7] = 0 Same as above
X[c(5,6,70}= c(10, 11, 12) equating 5th ,6th &7th to 10, 11 & 12 respectively
Courtesy : Dr. Jafar Ahmed Khan
Profesor, Dept. of Statistics, Biostatistics & Informatics, University of Dhaka

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