Receiving NaN message
Hi Robert, There is a policy of not doing people's homework for them on the list. Nevertheless, I would advise you to read up on how to use the comparison operator (==). Good luck. Jim On Tue, Jan 17, 2017 at 7:10 AM, Robert Piliero
<robert.piliero at gmail.com> wrote:
Hello,
I am working on a Coursera assignment and have combined 332 files into a
single data frame called "dat". The dataframe has 4 columns,
1. Date
2. Sulfate (numerical values)
3. Nitrate (numerical values)
4. ID # (numerical values).
Our assignment is to write a function pollutantmean <- function(directory,
pollutant, ID). whereby we can calculate the mean by inputting the
pollutant name and ID #.
I have reached the stage of subsetting the date e.g. by ID # 1-10, however
when I do so and then calculate the mean of this subset I receive the NaN
message (even though I have instructed R to disregard the "NA"'s).
*Beginning Code: *
getwd()
read.csv(specdata)
specdata <- ("C:/Users/rober/specdata")
list.files(specdata)
files_full <- list.files(specdata, full.names=TRUE)
files_full
dat <- data.frame()
for (i in 1:332){
dat <- rbind(dat,read.csv(files_full[i]))
}
str(dat)
mean(dat$sulfate, na.rm=TRUE)
*Code which generated the NaN message. *
dat1_10 <- dat[which(dat[,ID] ==1:10),]
mean(dat1_10$sulfate, na.rm=TRUE)
Am I making a mistake in subsetting the rows with ID's 1:10? Any advice
would be appreciated.
Thank you,
Robert
Robert J. Piliero
Cell: (617) 283 1020
38 Linnaean St. #6
Cambridge, MA, 02138
USA
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.