Question

In the below box, we have the planets_df data from some data camp exercises. Use the data below to answer the following questions.

(6) In the below box, we have the planets_df data from some data camp exercises. Use the data below to answer the following questions. > planets df planets 1 Mercury Terrestrial planet 2 Venus Terrestrial planet 3 Earth Terrestrial planet 4 5 Jupiter 6 Saturn type diameter rotation rings 58.64 FALSE 0.949-243.02 FALSE 1.00 FALSE 1.03 FALSE 0.41 TRUE 0.43 TRUE 0.72 TRUE 0.382 1.000 0.532 Gas giant 11.209 9.449 4.007 Mars Terrestrial planet Gas giant ranus Gas giant 8 Neptune Gas giant 3.883 0.67 TRUE

(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”]?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

(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 -

> planets_df[2, ] type diameter rotation rings 0.949-243.02 FALSE name 2 Venus Terrestrial planet

-------------------------------------------

(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 -

planets_df,3] 1] 0.382 0.949 1.000 0.532 11.209 9.449 4.007 3.883 planets_df$diameter [1] 0.382 0.949 1.000 0.532 11.209 9.449 4.007 3.883

-----------------------------------------------------------------

(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 -

> planets_df$diameter<1 [1 TRUE TRUE FALSE TRUE FALSE FALSE FALSE FALSE

-------------------------------------------------

(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 -

[1] Jupiter Saturn Uranus Neptune

Add a comment
Know the answer?
Add Answer to:
In the below box, we have the planets_df data from some data camp exercises. Use the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT