My data consists of samples, varying in type, on patients over time. This data is over 10197 observations long. A (small) example of my data is:
PatientName <- c("Jones", "Jones", "Jones", "Smith", "Smith", "Nixon", "Nixon", "Nixon")
SampleType <- c("Venous", "Arterial", "Capillary", "Venous", "Venous", "Venous", "Venous", "Capillary")
DayTested <- c("Monday", "Tuesday", "Wednesday", "Monday", "Monday", "Monday", "Monday", "Tuesday")
df <- data.frame(PatientName, SampleType, DayTested)
I now wish to include a unique ID for when there are repeat sample types on the same patient on the same day.
My anticipated output would be:
df$ID <- c(1,1,1,1,2,1,2,1)
This picks up repeat occurrences of "Smith"
and "Nixon"
who have repeat "Venous"
samples taken on a "Monday"
designated by the ID = 2. All other ID's would be equal to 1 as they are seperate samples, taken on seperate days.
Is this please possible to do in R?