Indeed!
I cannot find a lot of documentation on dataresqc and what there is is not that helpful.
Sorry I forgot to mention the tolower command. I just find it easier to work with lowercase names so
tolower(c("Other_ID", "City", "Modern_Country", "Lat.degN", "Lon.degE",
"Station_Elevation.m", "Start_Year", "End_Year" ))
gives us this.
[1] "other_id" "city" "modern_country" "lat.degn"
[5] "lon.dege" "station_elevation.m" "start_year" "end_year"
Can you tell me what the three columns are in the allfiles directory files? It looks like they are---from left to right---'year', 'month', 'temperature' ?
I wanted to know if that was the layout that you wanted for the files. It is usually easier to walk through each command without the loop for debugging.
You can run Milan
with
x <- read.table(allfiles[23], header = FALSE, fill=TRUE,
sep="\t",stringsAsFactors=FALSE, na.strings="-9999")
milan <- cbind(new_inventory[23 ,], x)
colnames(milan) <- tolower(c("Index","City", "Country", "Lat", "Lon", "Station Elevation",
"value_tmin","value_tmax","value_tavg","V1", "V2"))
milan
to see if it looks okay. I have the rows in *new_inventory * in the same alphabetical order as the filesnames in allfiles so they be indexed by row number.
I don't see why you should be getting an error at "Milan" either but R error messages can be very obscure at times and may come from something much earlier.
When you say you are having a problem with "Milan" does that mean you are getting usable output files for other stations?
I, frankly, cannot see how your code will work.
The more I look at your code the more I think you need to spend some time on very basic R to get a feel for R syntax and data handing. In some cases you are trying to to impossible things and in others the syntax just does not work. I suspect that you are thinking tha R behaves like other computer languages and it does not. It does really crazy things at times.
Working from my simple example.
sep="\t",stringsAsFactors=FALSE, na.strings="-9999")
gives us a data.frame with 3 columns.
Your command
colnames(x) <- c("City", "Lat", "Lon", "Station Elevation", "Date", "value_tmin","value_tmax","value_tavg","other")
Error in names(x) <- value :
'names' attribute [9] must be the same length as the vector [3]
cannot work as it is trying to assign 9 names to three columns.
This cannot work properly
months<- as.numeric(substr(x$Date,5,6))
as there is no Date variable with a character length of 6 in data.frame x. If fact I cannot see how there could be a variable called Date in x because of the namen problem.
The only thing that looks like a date is Column 1 which is a 4 digit integer, for example "1763" as the first row in the Milan data. If there was a 4 digit Date
it would return "".
xx <- 2020
substr(xx,5 , 6)
[1] ""
I am trying to decode the write_sef() statement at the moment and it is a bit confusing. To be honest a lot of the documentation is either confusing or non-existent. dataresqc looks to be a relatively new. I think it would be worth an email to the package author or maintainer to see if they can offer some pointers.
I noticed that the sample data Bern that is supplied with dataresqc actually is not a data.frame but is a list with 2 data.frames, ta and p
Do
str(Bern)
to see what I mean.
I am sorry to be of so little help.