In the below box, we have the planets_df data from some data camp exercises. Use the data below to answer the following questions.
(a)Write a line of code that gives me all the information about “Venus”.
(b) Write a line of code that gives me the ‘diameter’ variable.
(c) What would this line of code do: planets_df$diameter < 1?
(d) What would this line of code give us: planets_df$planets[planets_df$type == “Gas giant”]?
(a)
The data frame is named 'planets_df' and Venus is in its second row. So, you should use the following command -
> planets_df[2, ]
Note that there is empty space after comma (,) because we want the entire row data. The first element of square bracket reads the row number and second element reads the column number. So, leaving the second element empty gives us output as -
-------------------------------------------
(b)
Now, we need the entire column 3 and no specific row. So, you will leave the first argument blank and use 3 as second argument. So, you can use -
> planets_df[ , 3]
Note that you can also use the following code in this case -
> planets_df$diameter
Both give the same result shown below -
-----------------------------------------------------------------
(c)
You are aware of the fact that '<' is a relational operator such as '==', '>' or '!='.
So, putting this operator at the end of the variable 'diameter' will check each of its elements against the specified value which is 1 in this case.
So, it will read 'TRUE' if the diameter is less than 1 and 'FALSE' otherwise.
Here is the output -
-------------------------------------------------
(d)
Once again, note that you have put a logical check for the 'type' variable which is TRUE only if its 'Gas giant'. As you have used the '==' relational operator so it will only pass the rows which have the type 'Gas giant'. And then the code in front which is reading the planets name would read the name of planets which resulted in TRUE for the inner condition.
So, your output should contain the planets - Jupiter, Saturn, Uranus and Neptune.
The output is shown below -
In the below box, we have the planets_df data from some data camp exercises. Use the...
show calculations please! In Astronomy we often deal with distances, or lengths, that range form the very small to the very large. For instance The size of a nucleus is roughly 0.000, 000,000,000,001 meters and the distance to the nearest star is roughly 700,000,000,000 meters. We will talk about these numbers using scientific notation where each zero is counted as ten raised to an exponent equal to the number of zeros. Le the size of a nucleus is 1 x...