 I have a bunch of.csv files that share like a dozen different columns, including ones for "DateTime", "Abs Pres", and "Temp", among other things. I've written this code which creates a dataframe only displaying DateTime and Abs Pres but now I want to add the Temp column to that filtered dataframe, while still excluding the other columns. I've tried adding "starts_with(Temp) following the "starts_with(Abs Press) and "starts_with(Date)" but that doesn't work. I feel like I would need to include another if/then statement like the previous columns but I don't need it to actually manipulate the temperature data, I just need it to include that column in the dataframe. I've included a picture of what the working dataframe looks like, but I'd just like it to have one more column labeled "Temp" that matches the correct data point at the correct Date/Time.
I have a bunch of.csv files that share like a dozen different columns, including ones for "DateTime", "Abs Pres", and "Temp", among other things. I've written this code which creates a dataframe only displaying DateTime and Abs Pres but now I want to add the Temp column to that filtered dataframe, while still excluding the other columns. I've tried adding "starts_with(Temp) following the "starts_with(Abs Press) and "starts_with(Date)" but that doesn't work. I feel like I would need to include another if/then statement like the previous columns but I don't need it to actually manipulate the temperature data, I just need it to include that column in the dataframe. I've included a picture of what the working dataframe looks like, but I'd just like it to have one more column labeled "Temp" that matches the correct data point at the correct Date/Time.
HOBOPress <- (lapply(csv_filtered,function(x){
  print(x)
  try({
    d <- read_csv(x, skip=1,local = locale(encoding = "latin1") ) %>% 
      select(starts_with("Date"),starts_with("Abs Pres"), starts_with("Temp")) %>% 
      mutate(filename=x)
    if("Date Time, GMT-04:00" %in% names(d)){
      test <- mdy_hms(d$`Date Time, GMT-04:00`)-60*60
      d$DateTime <- ifelse(is.na(test),mdy_hm(d$`Date Time, GMT-04:00`)-60,test)
    }else {
      test <- mdy_hms(d$`Date Time, GMT-05:00`)
      d$DateTime <- ifelse(is.na(test),mdy_hm(d$`Date Time, GMT-05:00`),test)
    }
    if(any(str_detect(names(d),"psi"))){
      d$AbsPres <- 6.89476 * d %>% select(starts_with("Abs Pres")) %>% pull()
    }else{d$AbsPres <- d %>% select(starts_with("Abs Pres")) %>% pull() %>% 
      as.numeric()}
    d <- d %>% select(filename,DateTime,AbsPres,Temp)
  })
}))
