Select lists based on specific logic.

Hello,

I have a list of lists that are unique surveys and I am trying to find a way to only keep lists that meet a condition. For example, keep lists that contain the variable Q4 and Q4 must be numeric or integer.

I apologize for not being able to provide reproducible code at the moment. I am using an API to obtain my surveys from Qualtrics using this function. As you can see, I can't find the right way to filter these lists based on the logic that Q4 is numeric of integer. I was thinking that assertthat functions might work but no luck...

 GetQualSurvey <- function(token, user)
{
  registerOptions(api_token=token, root_url="")
  Surveys <- getSurveys() %>%
    filter(id %in% user) %>%
    select(id) %>%
    mutate(id = as.character(id))
  Vector <- Surveys[['id']]
  map(Vector, getSurvey, force_request = T, useLabels = F) %>%
    map2(Vector, ~mutate(.x, ID = .y)) %>%
    keep(~ assertthat::has_name(.x,"Q4")) %>%
    keep(~ assertthat::is.number(Q4)) %>%
    map(~ mutate(.x, Q4 = as.integer(Q4))) %>%
    map(~ select(.x, ResponseID, StartDate, EndDate,
                 RecipientEmail, Finished,Q4, ID)) %>%
    reduce(bind_rows)
    }

Thank you for the help!

Could you provide small Survey and Vector objects? Otherwise, it's very difficult to puzzle out. Also, please make sure to include records that include all of Q4 that you are testing for.

Thanks.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.