Hello! Thank you for your help in advance. I'm still getting my bearings with R and I am rubbish with loops
I have 1200 .txt files where the top 15 lines contain meta data, the bottom data contain the data readout (varying rows with 7 variables). I want to pull the "mac value" (row 9, column 2) from the top 15 lines and repeat that value in a new column with the other values of the data. I want to repeat this process for all 1200 sample files and then bind all the rows together to have a Masterlist. Here's an example for 2 of the .txt files. Any suggestions as how to set this up for all 1200 files would be greatly appreciated!!! Thank you!
df=read.csv("sample1.txt", nrows=15, sep="\t")
patb <- "mac*"
b <- grep(patb, df[9,2], value = TRUE)
df1=read_table("sample1.txt", skip = 15)
df1$macid=rep(b, nrow(df1))
df2=read.csv("sample2. txt", nrows=15, sep="\t")
patb <- "mac*"
b2 <- grep(patb, df2[9,2], value = TRUE)
df3=read_table("sample2.txt", skip = 15)
df3$macid=rep(b2, nrow(df3))
Master=rbind(df1, df3)
and @ddiez you are a rockstar yet again! Thanks this is working now and I was able to implement grep for inconsistencies. Thank you!!