Re: [R] dplyr summarize by groups

2024-11-30 Thread Rui Barradas
Às 05:52 de 23/11/2024, tgs77m--- via R-help escreveu: # Get mean, min, max sigma and skew by group options (digits = 3) library (ISwR data(energy) data %>% group_by(stature) %>% summarize( Mean = mean(expend), Min = min(expend), Max = max(expend), Sigma = sd(expe

Re: [R] 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

2024-11-30 Thread Rui Barradas
Às 02:27 de 01/12/2024, Sorkin, John escreveu: 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

Re: [R] 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

2024-11-30 Thread avi.e.gross
I was wondering along similar lines, Bert. One way to get help is to ask how to do some single step of a larger strategy. That can lead to answers that may not be as applicable to the scenario. Another way would be to include a synopsis of what they are trying to do. But, as John says he is try

Re: [R] 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

2024-11-30 Thread Bert Gunter
May I ask *why* you want to do this? It sounds to me like like you're using SAS-like strategies for your data analysis rather than R-like. -- Bert -- Bert On Sat, Nov 30, 2024 at 6:27 PM Sorkin, John wrote: > > Dear R help folks, > > First my apologizes for sending several related questions to

Re: [R] [External] 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

2024-11-30 Thread Richard M. Heiberger
tmp.ID <- unique(olddata$ID) Firsts <- match(tmp.ID, olddata$ID) newdata <- cbind(olddata, First=0) newdata$First[Firsts] <- 1 newdata newdata$FirstDay <- 0 for (id in tmp.ID) newdata$FirstDay[newdata$ID == id] <- newdata$date[newdata$ID == id][1] newdata > On Nov 30, 2024, at 21:27, Sorkin, J

Re: [R] 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

2024-11-30 Thread Christopher W. Ryan via R-help
Sorry, for completeness: library(dplyr) olddata %>% group_by(ID) %>% mutate(first = as.integer(row_number() == 1)) --Chris Ryan Christopher W. Ryan wrote: > Personally, I'd do this in the tidyverse with dplyr and its row_number() > function. > > olddata %>% group_by(ID) %>% mutate(first = as.i

Re: [R] 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

2024-11-30 Thread Christopher W. Ryan via R-help
Personally, I'd do this in the tidyverse with dplyr and its row_number() function. olddata %>% group_by(ID) %>% mutate(first = as.integer(row_number() == 1)) --Chris Ryan Sorkin, John wrote: > ID <- c(rep(1,10),rep(2,6),rep(3,2)) > date <- c(rep(1,2),rep(2,2),rep(3,2),rep(4,2),rep(5,2), >

Re: [R] 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

2024-11-30 Thread Ben Bolker
I think as.numeric(! duplicated(group)) might do this for you ... On Sat, Nov 30, 2024, 9:27 PM Sorkin, John wrote: > 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 diff

[R] 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

2024-11-30 Thread Sorkin, John
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 progra

Re: [R] Trying to get the prior value of a record from a data.frame . . . data.frame

2024-11-30 Thread Bert Gunter
I assume that the responses that John already received to his recent post met his needs. However, when I read it, I had a slightly different interpretation. So feel free to ignore the rest of this post if you like, but here's my interpretation and a simple solution to it. An example to help explai

Re: [R] Save spatial data in a csv file

2024-11-30 Thread Hasan Diwan
Kindly respond with the output of `dput(nyc_ct_geo)` -- thank you! -- H -- OpenPGP: https://hasan.d8u.us/openpgp.asc If you wish to request my time, please do so using *bit.ly/hd1AppointmentRequest *. Si vous voudriez faire connnaisance, allez a *bit.ly/hd1Ap

[R] Save spatial data in a csv file

2024-11-30 Thread D
> print(nyc_ct_geo) Simple feature collection with 2325 features and 1 field Geometry type: MULTIPOLYGON Dimension: XY Bounding box: xmin: 913175.1 ymin: 120128.4 xmax: 1067383 ymax: 272844.3 Projected CRS: NAD83 / New York Long Island (ftUS) First 10 features: geoid geometry 1 36061000100 MULTIPOL