You have some incorrect understandings of where you got the data. There is no such dataset in dplyr. How do I know this?
data(package="dplyr")
# ---- returns ---
Data sets in package ‘dplyr’:
band_instruments Band membership
band_instruments2 Band membership
band_members Band membership
starwars Starwars characters
storms Storm tracks data
There is a dataset named "pedestrian" in the naniar package and it does have entries that match values in the fragment of data imaged in the link (although the column names and column order are different). Specifically:
grep("Birrarung", (naniar::pedestrian$sensor_name) ) # returns 8455+1001 values)
But your dataset has too many entries to be an exact match. Your dataset has 66,037 lines, somewhat less than double the number of rows in naniar::pedestrian.
str(naniar::pedestrian)
tibble [37,700 × 9] (S3: tbl_df/tbl/data.frame)
$ hourly_counts: int [1:37700] 883 597 294 183 118 68 47 52 120 333 ...
$ date_time : POSIXct[1:37700], format: "2016-01-01 00:00:00" "2016-01-01 01:00:00" "2016-01-01 02:00:00" "2016-01-01 03:00:00" ...
$ year : int [1:37700] 2016 2016 2016 2016 2016 2016 2016 2016 2016 2016 ...
$ month : Ord.factor w/ 12 levels "January"<"February"<..: 1 1 1 1 1 1 1 1 1 1 ...
$ month_day : int [1:37700] 1 1 1 1 1 1 1 1 1 1 ...
$ week_day : Ord.factor w/ 7 levels "Sunday"<"Monday"<..: 6 6 6 6 6 6 6 6 6 6 ...
$ hour : int [1:37700] 0 1 2 3 4 5 6 7 8 9 ...
$ sensor_id : int [1:37700] 2 2 2 2 2 2 2 2 2 2 ...
$ sensor_name : chr [1:37700] "Bourke Street Mall (South)" "Bourke Street Mall (South)" "Bourke Street Mall (South)" "Bourke Street Mall (South)" ...
Your request seems a bit confusing. "My goal is to create a new dataset that exclude Date_Time column. Select() still keep Date_Time column." There is no column with that name in the pedestrian dataset (since capitalization needs to be exact), but if there were, it would be simple matter to exclude it:
new_dat <- old_dat[!"Date_Time" %in% names(old_dat)]
# And maybe
new_dat <- old_dat %>% select(-Date_Time)
It would also be a simple matter to destructively convert to character with:
new_dat$Date_Time <- as.character(old_dat$Date_Time)
Since you have not shown what code you tried and cannot even tell us where the data comes from, we can only speculate what you did and how you are failing.
Maybe someone else created a datset from the publicly accessible data at https://data.melbourne.vic.gov.au/Transport/Pedestrian-Counting-System-Monthly-counts-per-hour/b2ak-trbp
AHA! Found it!
https://tsibble.tidyverts.org/reference/pedestrian.html
str(pedestrian)
tbl_ts [66,037 × 5] (S3: tbl_ts/tbl_df/tbl/data.frame)
$ Sensor : chr [1:66037] "Birrarung Marr" "Birrarung Marr" "Birrarung Marr" "Birrarung Marr" ...
$ Date_Time: POSIXct[1:66037], format: "2015-01-01 00:00:00" "2015-01-01 01:00:00" "2015-01-01 02:00:00" "2015-01-01 03:00:00" ...
$ Date : Date[1:66037], format: "2015-01-01" "2015-01-01" "2015-01-01" "2015-01-01" ...
$ Time : int [1:66037] 0 1 2 3 4 5 6 7 8 9 ...
$ Count : int [1:66037] 1630 826 567 264 139 77 44 56 113 166 ...
- attr(*, "key")= tibble [4 × 2] (S3: tbl_df/tbl/data.frame)
..$ Sensor: chr [1:4] "Birrarung Marr" "Bourke Street Mall (North)" "QV Market-Elizabeth St (West)" "Southern Cross Station"
..$ .rows : list<int> [1:4]
.. ..$ : int [1:14566] 1 2 3 4 5 6 7 8 9 10 ...
.. ..$ : int [1:16414] 14567 14568 14569 14570 14571 14572 14573 14574 14575 14576 ...
.. ..$ : int [1:17518] 30981 30982 30983 30984 30985 30986 30987 30988 30989 30990 ...
.. ..$ : int [1:17539] 48499 48500 48501 48502 48503 48504 48505 48506 48507 48508 ...
.. ..@ ptype: int(0)
..- attr(*, ".drop")= logi TRUE
- attr(*, "index")= chr "Date_Time"
..- attr(*, "ordered")= logi TRUE
- attr(*, "index2")= chr "Date_Time"
- attr(*, "interval")= interval [1:1] 1h
..@ .regular: logi TRUE
And now I see that the inimitable Rob Hyndman is behind this project: https://robjhyndman.com/hyndsight/tsibbles/
And I guess I am a bit behind the times or perhaps I should say I'm behind the time series. There are over 500 hits for an SO search on "[r] tsibble". Now I need to ask; did this answer your question?
Testing:
new_ped <- pedestrian %>% select(-Date_Time) # fails
pedestrian$Date_Time <- as.character(pedestrian$Date_Time) # succeeds
The tsibble::pedestrian dataset is an S4 object and may not behave in the same manner as ordinary R objects. But my error was in using the wrong operator for column removal.
?select # need to choose dplyr version rather than MASS version
Need to use ! rather than "-":
new_ped <- pedestrian %>% select(!Date_Time)
> str(new_ped)
tibble [66,037 × 4] (S3: tbl_df/tbl/data.frame)
$ Sensor: chr [1:66037] "Birrarung Marr" "Birrarung Marr" "Birrarung Marr" "Birrarung Marr" ...
$ Date : Date[1:66037], format: "2015-01-01" "2015-01-01" "2015-01-01" "2015-01-01" ...
$ Time : int [1:66037] 0 1 2 3 4 5 6 7 8 9 ...
$ Count : int [1:66037] 1630 826 567 264 139 77 44 56 113 166 ...