Displaying 3 results from an estimated 3 matches for "dup_int".
2024 Dec 01
2
Identify first row of each ID within a data frame, create a variable first =1 for the first row and first=0 of all other rows
...y argument, which avoids explicit the call
> to group_by, with a performance gain.
>
>
> library(microbenchmark)
>
> mb <- microbenchmark(
> ave = with(olddata, ave(seq_along(ID), ID, FUN = \(x) x == x[1L])),
> dup_num = as.numeric(! duplicated(olddata$ID)),
> dup_int = as.integer(! duplicated(olddata$ID)),
> diff = diff = c(1L, diff(olddata$ID)),
> dplyr_grp = olddata %>% group_by(ID) %>% mutate(first =
> as.integer(row_number() == 1)),
> dplyr = olddata %>% mutate(first = as.integer(row_number() == 1), .by
> = ID)
> )
> p...
2024 Dec 02
0
Identify first row of each ID within a data frame, create a variable first =1 for the first row and first=0 of all other rows
...y argument, which avoids explicit the call
> to group_by, with a performance gain.
>
>
> library(microbenchmark)
>
> mb <- microbenchmark(
> ave = with(olddata, ave(seq_along(ID), ID, FUN = \(x) x == x[1L])),
> dup_num = as.numeric(! duplicated(olddata$ID)),
> dup_int = as.integer(! duplicated(olddata$ID)),
> diff = diff = c(1L, diff(olddata$ID)),
> dplyr_grp = olddata %>% group_by(ID) %>% mutate(first =
> as.integer(row_number() == 1)),
> dplyr = olddata %>% mutate(first = as.integer(row_number() == 1), .by
> = ID)
> )
> p...
2024 Dec 01
6
Identify first row of each ID within a data frame, create a variable first =1 for the first row and first=0 of all other rows
Dear R help folks,
First my apologizes for sending several related questions to the list server. I am trying to learn how to manipulate data in R . . . and am having difficulty getting my program to work. I greatly appreciate the help and support list member give!
I am trying to write a program that will run through a data frame organized by ID and for the first line of each new group of data