Note: All of the following is within R Studio Version 0.99.491
I'm trying to read a number of files (qty.50) Within these files there are a numebr of NA values so I need to exclude these and only count the number of complete rows.
As I output the result I'd like to alter the column name and order too.
I think I've got the reading files bit sorted but it's the counting complete rows bit and changing headers that I'm struggling with.
Any assistance would be very much appreciated.
EXAMPLE DATA
1.csv
Date Temp C Rain mm SensorID
01/01/2016 12:00 26.0 0.0 1
02/01/2016 12:00 24.3 0.0 1
03/01/2016 12:00 N/A 3.1 1
04/01/2016 12:00 17.5 2.0 1
05/01/2016 12:00 15.8 N/A 1
06/01/2016 12:00 22.6 N/A 1
2.csv
Date Temp C Rain mm SensorID
01/01/2016 12:00 9.0 6.2 2
02/01/2016 12:00 7.3 1.0 2
03/01/2016 12:00 14.1 0.0 2
04/01/2016 12:00 12.4 0.2 2
05/01/2016 12:00 N/A 2.9 2
06/01/2016 12:00 N/A N/A 2
My R function so far looks like this;
total_cases <- function(directory, id = 1:50) {
files_list <- list.files("temperatures", full.names=TRUE)
tempdf <- data.frame()
for (i in 1:50) {
tempdf <- rbind(tempdf, read.csv(files_list[i]))
}
tempdf_subset <- tempdf[which(!is.na(tempdf[, "ID"] %in% id),)]
nrow(temp_subset)
}
so ideally I'd like to put one of the following queries and get a response as shown below:
total_cases("temperatures", 1)
SensorID CountTemps
[1] 1 3
total_cases("temperatures", 2)
SensorID CountTemps
[1] 2 4
total_cases("temperatures", c(1,2)
SensorID CountTemps
[1] 1 3
[1] 2 4
Many thanks for all spending time on this. Matt