Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retaining columns with track_resample #121

Closed
peekaypee opened this issue Oct 30, 2024 · 3 comments
Closed

Retaining columns with track_resample #121

peekaypee opened this issue Oct 30, 2024 · 3 comments
Assignees

Comments

@peekaypee
Copy link

I have a couple of ID columns in my track (from make_track) that I would like retain in the subsequent step, i.e., track_resample. I want to use the ID columns to join some covariate information to the matched/random steps layer at a later stage. But track_resample removes those columns. How can I transfer these columns to my resampled track?

@jmsigner jmsigner self-assigned this Oct 30, 2024
@jmsigner
Copy link
Owner

Not sure I fully understand the questions. See the example below, what am I missing?

library(amt)
#> 
#> Attaching package: 'amt'
#> The following object is masked from 'package:stats':
#> 
#>     filter
library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union

dat <- data.frame(x = runif(10), y = runif(10), 
                  id = 1, id1 = 2, id3 = 3, 
                  t = now() + hours(0:9))

tr <- make_track(dat, x, y, t, all_cols = TRUE)
tr |> track_resample(rate = hours(2), tolerance = minutes(5))
#> # A tibble: 5 × 7
#>      x_     y_ t_                     id   id1   id3 burst_
#> * <dbl>  <dbl> <dttm>              <dbl> <dbl> <dbl>  <dbl>
#> 1 0.201 0.843  2024-10-30 19:43:17     1     2     3      1
#> 2 0.394 0.0112 2024-10-30 21:43:17     1     2     3      1
#> 3 0.305 0.199  2024-10-30 23:43:17     1     2     3      1
#> 4 0.154 0.507  2024-10-31 01:43:17     1     2     3      1
#> 5 0.638 0.129  2024-10-31 03:43:17     1     2     3      1

Created on 2024-10-30 with reprex v2.1.0

@peekaypee
Copy link
Author

peekaypee commented Oct 31, 2024 via email

@jmsigner
Copy link
Owner

You can use the argument keep_cols and then specificy if you want to keep them from the start or the end of the step or both. For id, I assume it does not really matter, since this wont change.

steps_by_burst(tr, keep_cols = "start")
steps_by_burst(tr, keep_cols = "end")
steps_by_burst(tr, keep_cols = "both")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants