mardi 17 février 2015

Unexpected '}' in R function. Something I miss?


Vote count:

0




I'm actually a n00b in all this; I'm in a Coursera's class and this is for my degree hw.


The instructions are:



pollutantmean <- function(directory, pollutant, id = 1:332) {
## 'directory' is a character vector of length 1 indicating
## the location of the CSV files

## 'pollutant' is a character vector of length 1 indicating
## the name of the pollutant for which we will calculate the
## mean; either "sulfate" or "nitrate".

## 'id' is an integer vector indicating the monitor ID numbers
## to be used

## Return the mean of the pollutant across all monitors list
## in the 'id' vector (ignoring NA values) }


So, according to this I made this:



pollutants <- function(directory, pollutant, id) {
fileName <- paste(formatC(id, width = 3, flag = "0"), ".csv", sep = "")
filePath <- paste(directory, "/", fileName, sep = "")
frame <- read.csv(filePath)
pollutantData <- frame[[pollutant]]
pollutantData[!is.na(pollutantData)] }


And then:



pollutantmean <- function(directory, pollutant, id = 1:332) {
pollutantLists <- sapply(id, function(id) pollutants(directory, pollutant, id))
pollutants <- unlist(pollutantLists)
mean(pollutants) }


So, neither, close or use the same window, I want to use these and something happen: because when I call my work source("pollutantmean.R"), tells me this error:



> source("pollutantmean.R")


Error en source("pollutantmean.R") : pollutantmean.R:10:1: inesperado '}' 9:

as.data.frame(matrix) 10: } ^
Something is wrong but I can't figure it out. PLEASE HELP!



asked 33 secs ago







Unexpected '}' in R function. Something I miss?

Aucun commentaire:

Enregistrer un commentaire