Removing variables from dataset but getting an empty dataset with only columns, no rows.

Hello, I am trying to run this code chunk to remove any variables with "HQ QR" value or a value of 0.

q4_2016_v2 <- q4_2016[!(q4_2016$start_station_name == "HQ QR" | q4_2016$ride_length < 0),]

glimpse(q4_2016_v2)

But when I run it, I receive a dataset without any rows, only columns. The glimpse reveals this:

Rows: 0
Columns: 19
$ ride_id            <chr> 
$ started_at         <dttm> 
$ ended_at           <dttm> 
$ rideable_type      <chr> 
$ tripduration       <int> 
$ start_station_id   <int> 
$ start_station_name <chr> 
$ end_station_id     <int> 
$ end_station_name   <chr> 
$ member_casual      <chr> 
$ start_date         <chr> 
$ start_time         <chr> 
$ end_date           <chr> 
$ end_time           <chr> 
$ date               <date> 
$ month              <chr> 
$ day                <chr> 
$ year               <chr> 
$ day_of_week        <chr> 

Do I need to use filter to fix this, or is it something else? Thanks

contradicts

here you are filtering to keep only values of 0 or more, if you want to remove rows with a value of 0, you should use q4_2016$ride_length == 0.

If what you want is to remove negative values, then your code looks correct, the simplest explanation is that there are simply no row with positive or 0 ride_length and start_station_name different from "HQ QR". Try running this to count entries in each group:

table(q4_2016$start_station_name == "HQ QR" , q4_2016$ride_length < 0)

Also, there is no column ride_length in your result of glimpse(), so that could indicate a problem.

This topic was automatically closed 42 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.