3

I'm a beginner using R to analyze a bunch of data. My program currently opens a list of csv's from a folder and binds them together into one data frame using rbind. Here's what it looks like:

LDT.list <- list.files(path="./Desktop/Data_analysis/LDT/", pattern=".csv", full.names = TRUE)
LDTfiles <- lapply(LDT.list, read.csv)
LDT_table <- do.call("rbind.data.frame" , LDTfiles)

The problem is that after using rbind, one of the columns in my dataframe is no longer numeric and I can't calculate its mean. I imported a single csv and the column I've described is considered numeric.The problem seems to occur after using rbind. I've already tried to convert the column to numeric but got a warning about missing data. So my question is how I could use rbind while keeping the classes as numerics. Thanks

  • 1
    It occurs because at least one of the data column from LDFfiles is s not numeric for that column, causing the whole column to convert to character with rbind. You may need to force the column to numeric in the list itself. i.e. `lapply(LDFfiles, function(x) {x[] <- lapply(x, as.numeric); x})` – akrun Jun 29 '21 at 21:15
  • 1
    it's likely that the column is imported as character on one or more of the files. you can look at sapply(LDT.list, sapply, typeof) for some insights – MichaelChirico Jun 29 '21 at 21:16
  • 4
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. When we can't see the data or run the code we can only guess as to what might be doing in which isn't a very efficient way to help. – MrFlick Jun 29 '21 at 21:20
  • 1
    After reading some comments I've discovered that there was a 'null' value in the column I was talking about! Thanks to the people who suggested analyzing each csv!!! – Rebeca Escobar Jun 29 '21 at 21:23

0 Answers0