I have hundreds of csv files (zoo objects in R) with 2 columns:
"Index","pp"
1951-01-01,22.9
1951-01-02,4.3
1951-01-03,4.6
I want the second column to have the name of each file. For example, when a filename is 02O_zoo.csv I would like the second column to be “02O” instead of “pp”. Is there an automatic way of doing this?
Thanks
(1) From files
read.zoocan take a character vector of file names as its first argument so:which gives this:
It would be possible to modify the names further if desired by placing names on the
Filenamesvariable, e.g.names(Filenames) <- gsub("testzoo|.csv", "", Filenames), or by modifying the names of the result, e.g.names(z) <- gsub("testzoo|.csv", "", names(z))(2) From zoo Objects. If they have been read in previously then try this:
which gives this:
The names of
zzcould be modified further as in the discussion above.