Message Boards Message Boards

1
|
1981 Views
|
3 Replies
|
7 Total Likes
View groups...
Share
Share this post:

How to filter planets according to conditions using SortBy?

I have a question I came up with that I would like to answer. What is the radius of all the planets who have at least one moon with a density that is greater than or equal to 0.55 times the density of Earth's moon? I have computed a dataset but I don't know how to filter with SortBy. For example the following code gives the number of moons Jupiter has that exeeds or equals Earth's moons density times 0.55

planets["Jupiter", "Moons", 
 Length@*Select[#Mass/(4/3 \[Pi] #Radius^3) > 
     0.55 (planets["Earth", "Moons", 
          Values, #Mass/(4/3 \[Pi] #Radius^3) &] // Normal // 
        First) &]]

I can also compute this for all planets with

planets[All, "Moons", 
 Length@*Select[#Mass/(4/3 \[Pi] #Radius^3) > 
     0.55 (planets["Earth", "Moons", 
          Values, #Mass/(4/3 \[Pi] #Radius^3) &] // Normal // 
        First) &]]

I tried the following code but it returned an empty list. It should return Earth, Mars, Jupiter, Saturn, and Neptune.

planets[Select[
  planets[#, "Moons", 
     Length@*Select[#Mass/(4/3 \[Pi] #Radius^3) > 
         0.55 (planets["Earth", "Moons", 
              Values, #Mass/(4/3 \[Pi] #Radius^3) &] // Normal // 
            First) &]] >= 1 &], "Mass"]

How can I finish my complex query? I am using

ExampleData[{"Dataset", "Planets"}]
POSTED BY: Peter Burbery
3 Replies

POSTED BY: Dave Middleton

I want to see the radius of the planets that meet the criterion, not the length. I figured out how to get the radius of planets:

planets[planets[All, "Moons", 
  Length@*Select[#Mass/(4/3 \[Pi] #Radius^3) > 
      0.55 (planets["Earth", "Moons", 
           Values, #Mass/(4/3 \[Pi] #Radius^3) &] // Normal // First) &]][Select[# > 0 &]]//Keys//Normal,"Radius"]
POSTED BY: Peter Burbery

Maybe this?

planets[All, "Moons", 
  Length@*Select[#Mass/(4/3 \[Pi] #Radius^3) > 
      0.55 (planets["Earth", "Moons", 
           Values, #Mass/(4/3 \[Pi] #Radius^3) &] // Normal // First) &]][Select[# > 0 &]]
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract