Gitta
Gitta

Reputation: 15

pivot longitudinal data into wider format: error due to attributes, also need to detect differences over time

I have longitudinal data and need to check whether contact info remained the same over time. A simple version would look like this

id<-c(1,1,2,2,2,3)
em1<-c("[email protected]",NA,"[email protected]",NA,NA,"[email protected]")
em2<-c(NA,"[email protected]",NA,"[email protected]",NA,NA)
em3<-c(NA,NA,NA,NA,"[email protected]",NA)
email<-tibble(id,em1,em2,em3)

I have 2 questions:

  1. using the above code I can run
    email_tidy<-email %>% 
      pivot_longer(em1:em3, values_to = "score",values_drop_na = TRUE) %>% 
      pivot_wider(id_cols = id, names_from = name, values_from  = score)

to get the wider format. However, in the real data this gives an error that "Some attributes are incompatible." I tried transforming to character but that resulted in a different error "Values from score are not uniquely identified".

  1. Suppose the first issue is solved and I have an "email_tidy" tibble, what would be an elegant way to get the most recent email, ignoring caps (ie. the only update would be [email protected])

Upvotes: 0

Views: 10

Answers (0)

Related Questions