Week 1 solution
Week 1 solution
Que1: Which of the following code will help in identifying the “NAs” in the Dataframe?
1. sum(is.na(DF)). Hint: This will identify the total NAs in the data.
2. sum(!is.na(DF)). Hint: This will identify observations that are not NA
3. !sum(is.na(DF)). Hint: Incorrect syntax. It will result in a “FALSE” output.
4. sum(is.finite(DF)). Hint: This will count the finite observations in the data.
Que2: Which of the following code will remove “NAs” in the Dataframe?
1. na.omit(DF). Hint: This will remove the observations (rows) that contain NAs.
2. sum(is.na(DF)). Hint: This will identify the total NAs in the data.
3. complete.cases(DF). Hint: This will identify those observations that are complete
in all senses and provide a logical TRUE/FALSE vector.
4. DF [!complete.cases(DF),]. Hint: This will create a new data frame with at least
one NA observation in each row.
Que3: Which of the following code can give the mean in a numeric vector containing
“NAs”?
1. Print ‘i’. Hint: The “%%” command returns the remainder, and the code prints
“Odd” when remainder is 0, that is the number is even, and prints Even, when
the remainder is one, that is the number is odd.
2. Print “Even” when ‘i’ is even and print “Odd” when ‘i’ is odd. Hint: The “%%”
command returns the remainder, and the code prints “Odd” when remainder is
0, that is the number is even, and prints Even, when the remainder is one, that is
the number is odd.
3. Print “Even” when ‘i’ is odd and print “Odd” when ‘i’ is even. Hint: The “%%”
command returns the remainder, and the code prints “Odd” when remainder
is 0, that is the number is even, and prints Even, when the remainder is one,
that is the number is odd.
4. Print “Even” ten times when ‘i’ is odd and print “Odd” ten times when ‘i’ is even.
Hint: The “%%” command returns the remainder, and the code prints “Odd”
when remainder is 0, that is the number is even, and prints Even, when the
remainder is one, that is the number is odd. Total printing is done 5-5, a total 10
times.
Que 6: The following code will provide the density distribution of a numeric
variable x.
1. plot(x). Hint: This will simply plot the observations in the vector.
2. hist(x). Hint: This will plot the frequency distribution of variable x.
3. hist(x, prob= T). Hint: This will plot the density distribution of x.
1. {0.0, 0.1, 0.2, 0.3, 0.4, 0.5}. Hint: The code will print a sequence starting from
0.0, ending at 0.5, with a gap of 0.1.
2. {0.1, 0.2, 0.3, 0.4, 0.5}. Hint: The code will print a sequence starting from 0.0,
ending at 0.5, with a gap of 0.1.
3. {0.0, 0.1, 0.2, 0.3, 0.4}. Hint: The code will print a sequence starting from 0.0,
ending at 0.5, with a gap of 0.1.
4. {0.1, 0.2, 0.3, 0.4, 0.5, 0.6}. Hint: The code will print a sequence starting from 0.0,
ending at 0.5, with a gap of 0.1.
quantile(0:100)
1. {1, 25, 50, 75, 100}. Hint: The code will print Minimum, 25%, Median, 75%, and
Maximum for a sequence of 0 to 100.
2. {1, 26, 51, 76, 100}. Hint: The code will print Minimum, 25%, Median, 75%, and
Maximum for a sequence of 0 to 100.
3. {0, 25, 50, 75, 99}. Hint: The code will print Minimum, 25%, Median, 75%, and
Maximum for a sequence of 0 to 100.
4. {0, 25, 50, 75, 100}. Hint: The code will print Minimum, 25%, Median, 75%,
and Maximum for a sequence of 0 to 100.