search for: firstday

Displaying 8 results from an estimated 8 matches for "firstday".

2024 Nov 27
7
R Processing dataframe by group - equivalent to SAS by group processing with a first. and retain statments
...nt in SAS and an if first.day statement and a retain statement: I want to take data (olddata) that looks like this ID Day 1 1 1 1 1 2 1 2 1 3 1 3 1 4 1 4 1 5 1 5 2 5 2 5 2 5 2 6 2 6 2 6 3 10 3 10 and make it look like this: (withing each ID I am copying the first value of Day into a new variable, FirstDay, and propagating the FirstDay value through all rows that have the same ID: ID Day FirstDay 1 1 1 1 1 1 1 2 1 1 2 1 1 3 1 1 3 1 1 4 1 1 4 1 1 5 1 1 5 1 2 5 5 2 5 5 2 5 5 2 6 5 2 6 5 2 6 5 3 10 3 3 10 3 SAS code that can do this is: proc sort data=olddata; by ID Day; run; data newdata; retai...
2024 Nov 27
4
R Processing dataframe by group - equivalent to SAS by group processing with a first. and retain statments
Check out the dplyr package, specifically the mutate function. # Create new column based on existing column value df <- df %>% mutate(FirstDay = if(ID = 2, 5)) df Repeat as needed to capture all of the day/firstday combinations you want to account for. Like everything else in R, there are probably at least a dozen other ways to do this, between base R and all of the library packages available. On Wednesday, November 27th, 2024 at...
2024 Nov 27
1
R Processing dataframe by group - equivalent to SAS by group processing with a first. and retain statments
...e this > ID Day > 1 1 > 1 1 > 1 2 > 1 2 > 1 3 > 1 3 > 1 4 > 1 4 > 1 5 > 1 5 > 2 5 > 2 5 > 2 5 > 2 6 > 2 6 > 2 6 > 3 10 > 3 10 > > and make it look like this: > (withing each ID I am copying the first value of Day into a new variable, FirstDay, and propagating the FirstDay value through all rows that have the same ID: > > ID Day FirstDay > 1 1 1 > 1 1 1 > 1 2 1 > 1 2 1 > 1 3 1 > 1 3 1 > 1 4 1 > 1 4 1 > 1 5 1 > 1 5 1 > 2 5 5 > 2 5 5 > 2 5 5 > 2 6 5 > 2 6 5 > 2 6 5 > 3 10 3 > 3 10...
2024 Nov 27
1
R Processing dataframe by group - equivalent to SAS by group processing with a first. and retain statments
Was wondering when this would be suggested. But the question was about getting the final dataframe... newdta <- olddta newdta$FirstDay <- ave(newdata$date, newdata$ID, FUN = \(x) x[1L]) On November 27, 2024 11:13:49 AM PST, Rui Barradas <ruipbarradas at sapo.pt> wrote: >?s 16:30 de 27/11/2024, Sorkin, John escreveu: >> I am an old, long time SAS programmer. I need to produce R code that processes a dataframe in...
2024 Nov 27
1
R Processing dataframe by group - equivalent to SAS by group processing with a first. and retain statments
...this > ID Day > 1 1 > 1 1 > 1 2 > 1 2 > 1 3 > 1 3 > 1 4 > 1 4 > 1 5 > 1 5 > 2 5 > 2 5 > 2 5 > 2 6 > 2 6 > 2 6 > 3 10 > 3 10 > > and make it look like this: > (withing each ID I am copying the first value of Day into a new variable, FirstDay, and propagating the FirstDay value through all rows that have the same ID: > > ID Day FirstDay > 1 1 1 > 1 1 1 > 1 2 1 > 1 2 1 > 1 3 1 > 1 3 1 > 1 4 1 > 1 4 1 > 1 5 1 > 1 5 1 > 2 5 5 > 2 5 5 > 2 5 5 > 2 6 5 > 2 6 5 > 2 6 5 > 3 10 3 > 3 1...
2010 May 20
1
Question about difftime()
Dear R experts, I have a question about the result of difftime() function: Does it take into account the different number of days in each month. In my example, I have the following: > firstDay [1] "2010-02-20" > lastDay [1] "2010-05-20 16:00:00" > difftime(lastDay,firstDay,units='days') Time difference of 89.625 days > When I count the days I get 88 days from 20/02/2010 to 20/05/2010 consequently the difference in days should be 87. On the contrary,...
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
2006 Jul 27
9
CalendarHelper
Has anyone had any luck using the CalendarHelper plugin at http://wiki.rubyonrails.com/rails/pages/CalendarHelper recently? I''m scratching my head over the following error when I look at any page in my application: NameError in CalendarController#index undefined local variable or method `date_format'' for #<CalendarController:0x24ccd4c> RAILS_ROOT: