Posts

R-Basic: Part II- concatenate, class(), names(), multi entry vector, vector coercion etc.

  Overview Create numeric and character vectors. Name the columns of a vector. Generate numeric sequences. Access specific elements or parts of a vector. Coerce data into different data types as needed. Sort vectors in ascending and descending order. Extract the indices of the sorted elements from the original vector. Find the maximum and minimum elements, as well as their indices, in a vector. Rank the elements of a vector in increasing order. Perform arithmetic between a vector and a single number. Perform arithmetic between two vectors of the same length. And Some sample Q/As Vector aka Variable The most basic units available in R to store data set are called vectors. A data set often has multiple variables. Vectors can be created using ‘c’ known as concatenate. country <- c( "Bangladesh" , "Cameroon" , "Croatia" ) codes <- c(Bangladesh = 880 , Cameroon = 237 , Croatia = 385 ) codes Bangladesh Cameroon Croatia 880 237 38

R-Basic Part 1: Creating Objects, For Loop (Five Little Monkeys Example)

  Creating Objects We use the term object to describe anything that is stored in R. Variables are examples, but objects can also be more complicated entities such as functions. Let’s create objects a, b, and c and assign some values to them. a <- 1 b <- 2 c <- - 4 #Can also be done using '=' sign but not recommended because it can create some confusions d = 3 e = 2 f = 4 # Creating more objects g <- 15 h <- 19 i <- 21 j <- 26 # Printing the saved objects on R console a;b;c;d;e;f      ## [1] 1 ## [1] 2 ## [1] -4 ## [1] 3 ## [1] 2 ## [1] 4           Checking the previously created objects [ ls() ] R uses Random Excess Memory to store the active objects. It makes no sense for the objects to stress the system when we don’t really need them. Or, sometime we want to check how many objects we have on the active workstation. In either case, we have to check for the objects, and we can do so using  ls()  function in R. ls() [1] "a" "b