Hi,
I was wondering if anyone would be able to help me in trying to remove duplicated values of a variable I have without affecting/removing values of other variables. I've tried using distinct() but to no avail as it shortens the dataframe by affecting all variables.
Attached the code and my ideal output below, thanks for any help.
library(tidyverse)
library(lubridate)
#Variables
patientid <- c("-2147483646", "-2147483646", "-2147483646", "-2147483646", "-2147483646", "-2147483646",
"-2147483646", "-2147483646", "-2147483646", "-2147483646", "-2147483646", "-2147483646",
"-2147483646", "-2147483646", "-2147483646", "-2147483646")
date <- c("2018-08-06", "2018-08-07", "2018-08-15", "2018-08-20", "2018-08-27", "2018-09-03", "2018-09-10",
"2018-09-17", "2018-09-24", "2018-10-01", "2018-10-08", "2018-10-15", "2018-10-22", "2018-10-29",
"2018-11-05", "2018-11-12")
week <- week(date)
adherence <- c(4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3)
#Sample dataframe
test.df <- data.frame(patientid, date, week, adherence)
#Ideal output
patientid date week adherence count
n dmy 32 4 4
n dmy 32 4 NA
n dmy 33 3 3
n dmy 33 3 NA