Need help turning character strings into numeric data frames

Goal

I am trying to use purrr::pmap() to go through a list of .txt files that I will left merge with a data frame. To do this, I need to pick out the values needed from these files and put them in a data frame. So far I have made it up to isolating the value's but I am not sure how to get them into the data frame. I am trying to make one data frame with the provided data whose columns are separated by the "\t". Thank you kindly for all the help.

I am sure there is a much cleaner approach than I have so far, sorry for the clunky logic.

Reprex

readr::read_lines('https://gitlab.com/Bryanrt-geophys/Thesis_GitHub/-/raw/Thesis/data/raw/slv/1_test_T2_V5_A18_3D/NS.SLV', 
                  skip_empty_rows = TRUE) %>%
   glue::trim() %>%
   stringr::str_trim() %>%
   stringi::stri_remove_empty() -> y
    
# this may be unecessary if the first element can be assigned as the names of the two columns of the desired data frame
 y[-1] %>% 
   str_split(pattern = "\\t") 
  

Hi bryanrt,

Does this help you forward?

library(tidyverse)

slv <- read_lines("https://gitlab.com/Bryanrt-geophys/Thesis_GitHub/-/raw/Thesis/data/raw/slv/1_test_T2_V5_A18_3D/NS.SLV", 
                  skip_empty_rows = T
                  ) %>% 
  as_tibble() %>% 
  separate(col = value, 
           into = c("time_ma", "m"), 
           sep = "\t", 
           fill = "right"
           ) %>% 
  ## remove redundant lines
  filter(!is.na(m)) %>% 
  ## change type for all columns to `double`
  map_df(as.numeric)
  ## change type for a specific column 
  # mutate(time_ma = time_ma %>% as.numeric())
  
slv %>% slice_head(n = 8)
#> # A tibble: 8 x 2
#>   time_ma     m
#>     <dbl> <dbl>
#> 1    1        0
#> 2    1.25    25
#> 3    1.5     50
#> 4    1.75    75
#> 5    2      100
#> 6    2.25    75
#> 7    2.5     50
#> 8    2.75    25

Created on 2021-02-15 by the reprex package (v1.0.0)

Lars, you are an incredible human being! This is exactly what I was looking for. The separate() function is golden.

This topic was automatically closed 7 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.