x
and print
its value.5 - 145
.x
.vec
vec
.[ ]
function.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?z
that contains the concatenation
result of x
and y
.w
by extracting all elements from
x
except the last onew
(“one” and “two”) and
extract the “one” element.g
that contains numbers from 1 to 20:
g
.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”
At the end, evaluate the length of g
, its
type
(Is it the same as before?) and its
class
.
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
?)
Create a new vector g3
by multiplying g
by g2
.
Use a logical vector (TRUE and FALSE) to extract the 3rd, 6th,
and 9th elements of g3
Hint: Use rep()
to
create the logical vector and store the result in a new vector
g4
.
Divide g
by g4
and store the result in
g5
. What happens? How long is g5
?
Concatenate all the vectors (g, g2, g3, g4, g5
) into
a new vector g6
. How many elements does g6
contain?
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.