Petra Lamborn 1 year ago
parent
commit
8c9ab714d9
2 changed files with 1022 additions and 0 deletions
  1. 13
    0
      4.R
  2. 1009
    0
      input4.txt

+ 13
- 0
4.R View File

@@ -0,0 +1,13 @@
1
+library(dplyr)
2
+library(stringr)
3
+library(tidyr)
4
+input <- readLines("input4.txt") %>% paste(collapse = "\n") %>% str_split("\n\n") %>% unlist() %>%str_replace_all("\n", " ")
5
+flds <- input %>% str_extract_all("[a-z]+:") %>% unlist() %>% unique() %>% str_replace(":", "")
6
+df <- data.frame(Orig = input)
7
+for (f in flds) {
8
+    df[[f]] <- str_extract(input, paste0(f, ":[a-zA-Z0-9#]+")) %>% str_replace_all(paste0(f, ":"), "")
9
+}
10
+df.valid <- df %>% drop_na(-cid)
11
+str(df)
12
+str(df.valid)
13
+nrow(df.valid)

+ 1009
- 0
input4.txt
File diff suppressed because it is too large
View File