Subset Error Help

I am trying to create a subset using only the Provider's Yellow Cab of DC and Hitch. I also want to keep the variables Provider, Payment Provider, Trip Time, Mileage, and Total Cost.

variables are retained.

My code and the error:

subset(Provider, subset (Yellow Cab of DC, Hitch), select (Provider, PaymentType, TripTime, Mileage, TotalCosts))
Error: unexpected symbol in "subset(Provider, subset (Yellow Cab"


To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

Can you please read the guide and try to make a proper reproducible example? A screenshot is not very useful.

The issue is that subset function has two parameters. Subset and Select. These parameters if named should be followed by equals = symbol, and then the thing that they should equal. Following them with brackets rather than equals is a syntax error

And just as an example of this and of a reproducible example, see below.

Note the first argument in the subset function is the data.frame. The second arguement is for how you'd like to subset that data.frame. And the third argument lets you select specific columns to keep (leave it blank to select all).

ex_df <- data.frame(
  c1 = c(1,2,3,4,5),
  c2 = c("a", "b","c","d","e")

subset(ex_df, c1 < 4, select = c(c2))
#>   c2
#> 1  a
#> 2  b
#> 3  c

Created on 2020-03-01 by the reprex package (v0.3.0)

This is my revised one;

subset= Provider subset= Yellow Cab of DC, Hitch select= Provider, PaymentType, TripTime, Mileage, TotalCosts

It still comes out with an error; Error: unexpected symbol in "subset= Provider subset"

Your syntax is incorrect.
The general form is

subset(mydataframe, subset=mylogicalcondition, select=myvariablestokeep)

The first mention of subset is a function call and therefore does need brackets.


Yellow Cab of DC, Hitch

Does not look like a condition. A condition would be something compared to something else. What are you wishing to compare ?

I want it to only consist of trips provided by Yellow Cab of DC and Hitch but also retain the variables Provider, PaymentProvider, TripTime, Mileage, and TotalCost

Ok :slight_smile: . I understand the concept. But not your data...
Do you have a variable and does the variable have possible values?
If you as a person tried to find the relevant roles you would look at column... For exact values of....

If you look above, I attached a picture and the variables are along the top.

Is that what you need?

as a general rule, pictures are a bad way to share information about data or code, and for best engagement with the community here, I strongly recommend taking the time to read through the suggested link [Subset Error Help]
However, because you are new, and need some time to absorb those recommendations, I'll help you out.

 subset=Provider %in% c("Yellow Cab of DC","Hitch"),
 select=c(Provider, PaymentType, TripTime, Mileage, TotalCosts))

Please take a look at our homework policy, we can give you some pointers but we are not here to do your work for you.

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