Any help in resolving the following errors will be appreciated:> pollutantmean <- function(directory, pollutant, id=1:332)+ file_inc <- list.files("specdata", full.names=TRUE)> dat <- data.frame() > for(i in 1:10) {+ dat <- rbind(dat, read.csv(file_inc[i])) + } Error in read.table(file = file, header = header, sep = sep, quote = quote, : object 'file_inc' not found> sulfate <- subset(dat( , 2))Error in subset(dat(, 2)) : could not find function "dat"> nitrate <- subset(dat( , 3))Error in subset(dat(, 3)) : could not find function "dat"> mean(pollutant)Error in mean(pollutant) : object 'pollutant' not found> save"pollutantmean.R"Error: unexpected string constant in " save"pollutantmean.R"" [[alternative HTML version deleted]]
A useful rule is to fix the first error you understand and hope that the others go away. On 04/09/2016 04:05, Tamar Michaeli wrote:> Any help in resolving the following errors will be appreciated: > >> pollutantmean <- function(directory, pollutant, id=1:332) > + file_inc <- list.files("specdata", full.names=TRUE)So what did you hope your function was going to do, if you called it?>> dat <- data.frame() >> for(i in 1:10) { > + dat <- rbind(dat, read.csv(file_inc[i])) > + } > Error in read.table(file = file, header = header, sep = sep, quote = quote, > : > object 'file_inc' not foundWhy did you think at this point that you had an object called file_inc?>> sulfate <- subset(dat( , 2)) > Error in subset(dat(, 2)) : could not find function "dat"So you did not manage anywhere to define a function called dat.>> nitrate <- subset(dat( , 3)) > Error in subset(dat(, 3)) : could not find function "dat" >> mean(pollutant) > Error in mean(pollutant) : object 'pollutant' not foundYou have never defined it.>> save"pollutantmean.R" > Error: unexpected string constant in " save"pollutantmean.R""?save might help you here.> > [[alternative HTML version deleted]] >Please do not post in HTML as it makes your post unreadable.> ______________________________________________ > 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. >-- Michael http://www.dewey.myzen.co.uk/home.html
pretty sure you just missed the `{` at the beginning of the `function`
definition block.
On Sun, Sep 4, 2016 at 7:38 AM, Michael Dewey <lists at dewey.myzen.co.uk>
wrote:
> A useful rule is to fix the first error you understand and hope that the
> others go away.
>
> On 04/09/2016 04:05, Tamar Michaeli wrote:
>
>> Any help in resolving the following errors will be appreciated:
>>
>> pollutantmean <- function(directory, pollutant, id=1:332)
>>>
>> + file_inc <- list.files("specdata", full.names=TRUE)
>>
>
> So what did you hope your function was going to do, if you called it?
>
> dat <- data.frame()
>>> for(i in 1:10) {
>>>
>> + dat <- rbind(dat, read.csv(file_inc[i]))
>> + }
>> Error in read.table(file = file, header = header, sep = sep, quote
>> quote,
>> :
>> object 'file_inc' not found
>>
>
> Why did you think at this point that you had an object called file_inc?
>
> sulfate <- subset(dat( , 2))
>>>
>> Error in subset(dat(, 2)) : could not find function "dat"
>>
>
> So you did not manage anywhere to define a function called dat.
>
> nitrate <- subset(dat( , 3))
>>>
>> Error in subset(dat(, 3)) : could not find function "dat"
>>
>>> mean(pollutant)
>>>
>> Error in mean(pollutant) : object 'pollutant' not found
>>
>
> You have never defined it.
>
> save"pollutantmean.R"
>>>
>> Error: unexpected string constant in "
save"pollutantmean.R""
>>
>
> ?save might help you here.
>
>
>
>> [[alternative HTML version deleted]]
>>
>>
>
> Please do not post in HTML as it makes your post unreadable.
>
>> ______________________________________________
>> 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/posti
>> ng-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
> --
> Michael
> http://www.dewey.myzen.co.uk/home.html
>
>
> ______________________________________________
> 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/posti
> ng-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
> On Sep 3, 2016, at 8:05 PM, Tamar Michaeli <tmichaeli001 at gmail.com> wrote: > > Any help in resolving the following errors will be appreciated: > >> pollutantmean <- function(directory, pollutant, id=1:332) > + file_inc <- list.files("specdata", full.names=TRUE) >> dat <- data.frame() >> for(i in 1:10) { > + dat <- rbind(dat, read.csv(file_inc[i])) > + } > Error in read.table(file = file, header = header, sep = sep, quote = quote, > : > object 'file_inc' not found >> sulfate <- subset(dat( , 2)) > Error in subset(dat(, 2)) : could not find function "dat" >> nitrate <- subset(dat( , 3)) > Error in subset(dat(, 3)) : could not find function "dat" >> mean(pollutant) > Error in mean(pollutant) : object 'pollutant' not found >> save"pollutantmean.R" > Error: unexpected string constant in " save"pollutantmean.R""This is pretty clearly an effort at solving a homework problem for Peng's R Coursera course. Homework questions are off-topic on Rhelp (and are not really encouraged on StackOverflow but you can probably find a worked example there by searching on " [r] pollutant list.files specdata".) When I tried out the course a few years ago the the participants were advised to post their questions at a website established for the course. -- David.> > [[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.