Creation of a new object

I have an existing data set called Olympics. I need to create a new object using dplyr that's a copy of this data set. It has to contain only records concerning "Tennis", sorted by 'Year', oldest last, and then alphabetically by 'Name' and 'Event', in that order. I also need to add a new final column, 'Prize'. For each record, it should contain 'True' if a medal was won by that competitor in that event and 'False' otherwise.

I need to do the same using base R.

The data set Olympics has info on the participants of all the sports events held at the Summer and Winter Olympics from 2010-2016. Each row is a separate record. The 'Height' column is in cm and the 'Weight' column in in Kg. The 'NOC' column indicates the 'National Olympics Committee' that sent each athlete

Welcome to Community!

So that we can better help you, what have you tried already?

Hi, I started like this:

new_olympics <- olympics[order(as.Year(olympics$Tennis, format= "oldest.last))

But I'm not sure if it's correct. (I'm sorry I really new to all this)

No worries! You're in the right place. :slight_smile:

Is this a homework question? If it is, I'd rather help guide you to the answer rather than do the work for you so that you learn something. Take a quick look at our homework policy: FAQ: Homework Policy.

What happens when you run the code you described? What are some error messages you're seeing? If you can provide a minimally reproducible example (FAQ: What's a reproducible example (`reprex`) and how do I create one?) I could get a better idea of what you're facing.


Nope this isn't homework.

When I ran the code it says: Error in olympics[order(as.Year(olympics$Tennis, format= "oldest.last)) could not find function "as.Year".

I checked online and they said to use as.Year to sort it by Year. But it doesn't seem to work

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.