Q:

Read special CSV-Data with a loop

I have a little problem and I'm sure you guys can help me!  I have a file folder in the directionary folder that consists of over 2000 .csv files. It's called "all Data".  I want to read them in R and save them in vectors.  I KNOW that this has been asked here before ... so this is what I've got:
setwd("C:/Users/Flo Chi/Documents/all Data")
ldf <- list()
csvliste <- dir(pattern="*.csv")
for(i in 1:length(csvliste)){ldf[[i]] <- read.csv(csvliste[i])}

My problem is the CSV Data itself!  As you can see in the picture e.g. "3327" has a comma on both sides.  If you transfer it into an excel file the numbers that I want (3327, etc.)  are in column B then.  I want only those numbers as a vector in ldf[[i]]!  
Do you know how this works? 
Thanks a lot for your answers! 

A:

There are a couple approaches you could take, if you assume that the only possible data forms are a) there is only one column of numeric data, or b) if there are two columns, the first column is all missing.   
The example below uses the second column anytime it finds a data frame with only missing values in the first column.   But it wouldn't be hard to adjust it to just take the second column whenever there are two columns (regardless of what is in the first column)
setwd("C:/Users/Flo Chi/Documents/all Data")
ldf <- lapply(dir(pattern = "*.csv"),
        function(i){
            df <- read.csv(i)
            if (all(is.na(df[, 1]))) df <- df[, 2, drop=FALSE]
            df
        })

