Hi. I am having a problem modifying a column of an appended data frame. I used the map_df() function to append the datasets and create a new column entitled 'gauge.location'. The row names for that column correspond to different river gauge locations in Ireland. I read in and appended the datasets with the following code:
myread <- function(mfile) {
t1 <- read.csv(mfile)
t1 <- mutate(t1, gauge.location = mfile)
}
MDF <- list.files(pattern = "*.csv") %>%
map_df(~ myread(.))
However, the problem is that the location names all have the suffix 'MDF.csv'. Thus instead of a row label referring only to the location of a particular river gauge, e.g., 'Antrim', it reads 'Antrim MDF.csv' instead. Because I have eight appended datasets corresponding to eight different locations, I need to remove the MDF.csv suffix from all the locations names (see the output below for an example).
DT.Index FQ. .m3.s. gauge.location
1 01/01/2015 09:00 8.805 Antrim MDF.csv
2 02/01/2015 09:00 7.260 Antrim MDF.csv
3 03/01/2015 09:00 7.626 Antrim MDF.csv
4 04/01/2015 09:00 6.168 Antrim MDF.csv
5 05/01/2015 09:00 5.623 Antrim MDF.csv
6 06/01/2015 09:00 6.153 Ballinderry MDF.csv
7 07/01/2015 09:00 11.009 Ballinderry MDF.csv
8 08/01/2015 09:00 7.007 Ballinderry MDF.csv
9 09/01/2015 09:00 8.627 Ballinderry MDF.csv
10 10/01/2015 09:00 9.042 Ballinderry MDF.csv
This is what I am trying to do:
DT.Index FQ. .m3.s. gauge.location
1 01/01/2015 09:00 8.805 Antrim
2 02/01/2015 09:00 7.260 Antrim
3 03/01/2015 09:00 7.626 Antrim
4 04/01/2015 09:00 6.168 Antrim
5 05/01/2015 09:00 5.623 Antrim
6 06/01/2015 09:00 6.153 Ballinderry
7 07/01/2015 09:00 11.009 Ballinderry
8 08/01/2015 09:00 7.007 Ballinderry
9 09/01/2015 09:00 8.627 Ballinderry
10 10/01/2015 09:00 9.042 Ballinderry
The data frame consists of 11688 observations and 3 variables. Two of the three variables (i.e.,'DT.Index' and 'gauge.location') are character variables, whereas the third variable (FQ..m3.s.) is numeric. This is my first post on here, so apologies if I haven't structured this post in the conventional way.
Kind regards
Gary