R:: Making a loop to edit each column in a large dataframe

Viewed 24

Let me preface this by saying I am new here, so please let me know if I missed anything.

I am working with a large number of xml files: extracting specific variables and putting them in a large data frame. Unfortunately, due to the formatting (or perhaps my poor coding), some of the variables end up as a list. For example, one variable (Monoplanar2CV_EDV) looks something like this: c(val = "183.267", unit = "ml"). I only care for the value (183.267). Each of those variables has its own column.

I am quite the beginner at coding and R, this is what I came up with to replace it with just the value:

test = as.data.frame(df$Monoplanar2CV_EDV)
test = head(test, 1)
colnames(test) = NULL
df_transpose = t(test) 
df$Monoplanar2CV_EDV = df_transpose

Now, I want to do the same thing for all the columns (a total of 156). Can someone help me figure out a loop or another way to address this issue efficiently? I would rather not write 5 lines of code for each column haha

Thanks!

0 Answers
Related