Operations in R

  1. Sum 2 and 3.

  1. Take the square root of 36.

  1. Take the logarithm in base 10 of 1000.

  1. Take the logarithm in base 2 of 32.

  1. Assign the sum of 2,3 and 4 to the variable x and print its value.

  1. Find the absolute value of the expression 5 - 145.

  1. Calculate the square root of 625, divide it by 5, and assign it to variable x.

Vectors

  1. Create a vector containing the values 1, 2, 3, 5 and 10, and assign it to the variable vec

  1. Check the length of your vector vec.

  1. Make a character vector of length 8 and then extract the 5th and 6th values using [ ] function.

  1. Make two vectors: x, that contains the numbers 2, 3, 4, 5 and y, that contains 100, 200, 300 and 400. What happens if you try to multiply them?

  1. Create the vector z that contains the concatenation result of x and y.

  1. Create the vector w by extracting all elements from x except the last one

  1. Assign names to the elements in w (“one” and “two”) and extract the “one” element.

  1. Create a vector g that contains numbers from 1 to 20:
    1. Evaluate the type of g.
    2. Perform the following modifications on g printing the vector after each step:
  • Add 2 to the first two elements

  • Multiply the elements from the 16th to the 20th by 30

  • Compute the square root of the elements from the 3rd to the 6th

  • Compute the logarithm (base 10) of all elements except the 9th

  • Divide by 2 the elements from the 10th to the 12th

  • Multiply the 15th element by pi number

  • Assign names to the elements of g: "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T"

  • Raise elements “C”, “D” and “O” to the 5th power

  • Subtract 10 from elements “H”, “M” and “R”

  • Compute the absolute value of all elements except “M” and “S”

  1. At the end, evaluate the length of g, its type (Is it the same as before?) and its class.

  2. Create a new vector g2 that has the same elements as g but with reverse order.
    Hint: use g and the : (what happend if you type 20:1?)

  3. Create a new vector g3 by multiplying g by g2.

  4. Use a logical vector (TRUE and FALSE) to extract the 3rd, 6th, and 9th elements of g3Hint: Use rep() to create the logical vector and store the result in a new vector g4 .

  5. Divide g by g4 and store the result in g5 . What happens? How long is g5?

  6. Concatenate all the vectors (g, g2, g3, g4, g5) into a new vector g6. How many elements does g6 contain?

  7. If you have finished all the previous exercises you can check https://www.javatpoint.com/r-built-in-functions for some others math functions in R.