How to store the contents of a variable from a dataset into another variable

Hey, I'm a new user of Rstudio and I'm following a swirl tutorial to understand the program. One of the tasks I've been given was to 'store the contents of the 'cars$mpgCity' in a new variable called 'myMPG'. How can I do that given that 'cars$mpgCity' is already a variable and the variable 'myMPG' doesn't exist?

I quibble that cars$mpgCity is not itself a variable, it is a subset of the variable cars. It is not bound to a separate name. In any case, you can make a new variable like this.

myMPG  <- cars$mpgCity

Thank you so much, I've been stuck with this all afternoon!

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