Exercises:¶
N.B.: before starting any exercise that involves random numbers, set the seed to 1303 (i.e., execute set.seed(1303))
- Given a number n, generate a list containing the first n integer numbers starting from 5.
- Given two numbers a and b, compute the sum of the numbers between a and b.
- Given a number n, compute the factorial of n. The factorial of a number n can be defined as product of all positive numbers less than or equal to n.
- Consider a vector x <- c(4,5,8,10,3,5,13), what is the value of x<7?
- Create a list with all odd numbers in the even positions and vice-versa.
- Create a list A with all random numbers. Then, create a list B containing only the odd elements of A and a list C containing only the even elements of A.
- Create a list A with all random numbers. Then, create a list B containing all the elements of A multiplied by 4.
- Create a 10x10 matrix with all random numbers from a normal distribution.
- Create a 10x10 matrix which general element M[i][j] has value equal to (i+1)*(j+1).
- Create a 10x10 matrix with all random numbers from a normal distribution. Then, sum all the element of the principal diagonal.
- Generate 1000 random numbers of a Gaussian with mean = 50 and std dev. = 3. Then draw a plot to show the distribution of the data.
- Write a while loop that prints out 10 standard random normal numbers.
- Write a for loop that iterates over the numbers 1 to 7 and prints the cube of each number using print().
- Create a vector 'age' with four integer example values of age, create a vector 'name' of four strings with four name examples, create a vector 'gender' with four elements with values equal to 'M' or 'F'. Then, create a dataframe which rows are four records and columns are 'age', 'name' and 'gender' contained in the previous defined vectors.