I was creating a new data frame but it seems have a problem creating another, what should I do
it seems from the screenshot, that you have a belief that there is a column called start_station_name
, but also evidence that there is no such column.
table(all_trips$member_casual)
all_trips$date <- as.Date(all_trips$started_at)
all_trips$month <- format(as.Date(all_trips$date), "%m")
all_trips$day <- format(as.Date(all_trips$date), "%d")
all_trips$year <- format(as.Date(all_trips$date), "%Y")
all_trips$day_of_week <- format(as.Date(all_trips$date), "%A")
all_trips <- bind_rows(q1_2019, q1_2020)#, q3_2019)#, q4_2019, q1_2020)
all_trips <- structure(list(started_at = c("1/1/2019 0:04", "1/1/2019 0:08",
"1/1/2019 0:13", "1/1/2019 0:13", "1/1/2019 0:14", "1/1/2019 0:15",
"1/1/2019 0:16", "1/1/2019 0:18", "1/1/2019 0:18", "1/1/2019 0:19"),
ended_at = c("1/1/2019 0:11", "1/1/2019 0:15", "1/1/2019 0:27",
"1/1/2019 0:43", "1/1/2019 0:20", "1/1/2019 0:19", "1/1/2019 0:19",
"1/1/2019 0:20", "1/1/2019 0:47", "1/1/2019 0:24")),
row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame"))
all_trips$started_at <- as.POSIXct(all_trips$started_at, format = "%m/%d/%Y %H:%M")
all_trips$ended_at <- as.POSIXct(all_trips$ended_at, format = "%m/%d/%Y %H:%M")
all_trips$date <- as.Date(all_trips$started_at)
all_trips$month <- format(all_trips$date, "%m")
all_trips$day <- format(all_trips$date, "%d")
all_trips$year <- format(all_trips$date, "%Y")
all_trips$day_of_week <- format(all_trips$date, "%A")
all_trips$ride_length <- difftime(all_trips$ended_at,all_trips$started_at)
all_trips
all_trips$ride_length <- difftime(all_trips$ended_at,all_trips$started_at)
str(all_trips)
is.factor(all_trips$ride_length)
all_trips$ride_length <- as.numeric(as.character(all_trips$ride_length))
is.numeric(all_trips$ride_length)
all_trips_v2 <- all_trips[!(all_trips$start_station_name == "HQ QR" | all_trips$ride_length<0),]
In the beginning of analysis there is called start_station_name in the data frame but when I wrote the code here the start_station_name disappear
This is the whole code chucnk I wrote but somewhere here when i am entering the codes the start_station_name disappear, So I think the problem here is the code I wrote.
A handy way to supply some sample data is the dput() function. In the case of a large dataset something like dput(head(mydata, 100)) should supply the data we need. Just do dput(mydata) where mydata is your data. Copy the output and paste it here between
```
```
The line all_trips <- structure(...)
replaces the previous value of all_trips with tibble containing two columns, started_at
and ended_at
. Everything else previously in all_trips
is gone. Subsequent lines create a bunch of additional columns but not a start_station_name
column. It's not clear why you build up all_trips
in the first several lines, then throw it away and start over, but in any event that's why start_station_name
disappears.
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.