Importing .CSV using a list in R -


So I have 29 data files that I want to load in R. The files are called "1.csv", "2", ".csv" etc. All the way 29. Here is the code that I am trying to do:

  file.number & lt ; - c (1:29) "value file.number" .data and lt; - read.csv ("value in file.number" ".csv")   

Actually I On the basis of one, I am searching for a path to load the code, and label it accordingly. Is it possible?

Any help would be greatly appreciated!

This will probably work

  dfList <- setNames (lapply (paste0 ( 1:29, ".csv" ), Read.csv), paste 0 (1:29, ".data"))   

Now you've got a named list of 29 data frames. You can access it with the $ operator, e.g., dfList $ "4.data" . Note that you will need quotes or backtacks because you have names with a digit You can avoid using [[ elements to use dfList [["" 4.data "]] , or as paste0 Can change in different names ( "Data", 1:29) , or any name that does not begin with any points.

Another option would be map

  map (read.csv, paste0 (1:29, ".csv"))   

This will automatically set the names of the files to be read, namely, 1.csv , 2.csv , etc. Again, brackets or quotations will be required to reach the elements with the $ operator because the names begin with the digits.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -