Hi @Cepheides,
Your data is pretty "messy" but does have a regular structure.
I was able to read the data from a txt file using this approach:
# Find the total lines in the txt file, hence the number of data "groups"
con <- file("testing_input.txt")
in_len <- length(readLines(con, warn=FALSE))
groups <- (in_len-7)/8
# Pre-define data frame to contain output
out_df <- data.frame(row.names=1:groups)
# Read each group of data, make into one row
for(ii in 1:groups) {
if (ii == 1) (skip_value = 7) else (skip_value = 7 + (ii-1)*8)
dat <- read.table(file="testing_input.txt", skip=skip_value,
header=FALSE, fill=TRUE, nrows=7)
mat <- t(as.matrix(dat))
wide_mat <- matrix(mat, nrow=1, ncol=35, byrow=TRUE)
trim_mat <- matrix(wide_mat[, -c(5,10,12:15)], nrow=1, ncol=29, byrow=TRUE)
out_df[ii, 1:29] <- as.data.frame(trim_mat)
print(paste("DONE group", ii))
}
names(out_df) <- c("MassCol", "T", "Pg", "Pe",
"Ne", "N_HI", "N_HII", "N_H-",
"N_H- / Ne",
"C_I", "Si_I", "Fe_I", "Mg_I", "Ni_I",
"Cr_I", "Ca_I", "Na_I", "K_I", "He_I",
"C_II", "Si_II", "Fe_II", "Mg_II", "Ni_II",
"Cr_II", "Ca_II", "Na_II", "K_II", "He_II")
out_df <- out_df[complete.cases(out_df), ]
head(out_df)
Not elegant but it gets the job done!