1.

Create a vector called x with the elements:

1, 4, -7, 11, NA, 9, 2, 1, NA, 1, 4, 0

Compute the natural log of each value and print the results.

>  [1] 0.0000000 1.3862944       NaN 2.3978953        NA 2.1972246 0.6931472
>  [8] 0.0000000        NA 0.0000000 1.3862944      -Inf


2.

Create the following three strings:

  • a = "This is",
  • b = "a concatenated",
  • c = "string".

Using these, create a new string called d that is This is a concatenated string. Print d.

> [1] "This is a concatenated string"


3.

Create a logical vector called g with the values:

T, T, T, T, F, T, T, T, F, T, T, T.

The vector x refers to the one created in Question 1. Complete the following tasks:

(1) Using g, create a variable called z that is the sum of the non-NA values in x. Print z.
(2) Change the third position of g to F, and using g, compute the natural log of all the values that are at least 0 in x. Print the result.
> [1] 26
> [1] 0.0000000 1.3862944 2.3978953 2.1972246 0.6931472 0.0000000 0.0000000
> [8] 1.3862944      -Inf


4.

Using the rep() function (We mentioned in chapter 2), create a vector j that consists of

1, 2, 1, 2, 1, 2, 1, 2, 1, 2,

and a vector k that consist of

1, 1, 2, 2, 3, 3, 4, 4, 5, 5.

Using seq(), create a vector q that consist of

0.0000000, 0.5555556, 1.1111111, 1.6666667, 2.2222222,

2.7777778, 3.3333333, 3.8888889, 4.4444444, 5.0000000.

Using these three vectors, compute and print out the square root of the sum of the squares of j, k, and q.

(That is, \(\sqrt{\sum_i(j_i^2+k_i^2+q_i^2)}\).
> [1] 14.93194