Skip to main content

Posts

Showing posts with the label basic numerical commands

Basic commands in R

Basic numerical commands Assign a value: x = 4 #Assign a value x ## [1] 4 x = 3 ; x = 5 #the value of the variable is the last that has been assigned. ";" separetes different steps. x ## [1] 5 Sequences: x = 1 : 10 #Sequence from 1 to 10 x ## [1] 1 2 3 4 5 6 7 8 9 10 vec = c ( 1 , 2 , 3 , 4 , 5 ) # c(): function that combines its arguments. vec ## [1] 1 2 3 4 5 x = 1 : 3 ; y = 3 : 5 ; z = 5 : 7 vec1 = c ( x , y , z ) #c() combines the values of x,y,z vec1 ## [1] 1 2 3 3 4 5 5 6 7 rep()  function: rep()  3 arguments: an object (vector, factor, etc) to be repeated  times : number of times to repeat each object  lenght.out : lenght of the output vector  each : times each element of the object is repeated x = 1 : 5 rep ( x , 2 ) # 2 times the x sequence ## [1] 1 2 3 4 5 1 2 3 4 5 rep ( x , each = 2 ) # 2 times each value in the seq ## [1] 1 1 2 2 3 3 4...