Skip to content

Commit c9ec257

Browse files
committed
Update FAQ.md
1 parent f4d59dc commit c9ec257

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

FAQ.md

+20
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,44 @@ You're not submitting via the Coursera website are you? You need to re-read the
77

88
Instead of submitting via the website, you need to use the `submit()` script. A link and more detailed instructions are included in the "Grading" section of the assignment 1 instructions.
99

10+
1011
####2) Do I need to round my answers to match the sample output?
1112

1213
No. You don't need to do any rounding to your results to pass the submission tests.
1314

15+
1416
####3) I only see 3 parts to the assignment. What are these 10 parts listed on the assignment page?
1517

1618
You're correct that there are only 3 parts to assignment 1. The 10 parts could probably me more accurately described as tests. The `submit()` script will run your code with a variety of different parameters to test it. If there are issues with your function, it may only pass some of thests.
1719

20+
1821
####4) My `pollutantmean()` passes the first 3 tests, but fails the 4th with the error message: "Error in pollutantmean("specdata", "nitrate") :
1922
argument "id" is missing, with no default"
2023

2124
You didn't assign a default value to `id`. The first line of your function should look exactly like the one in the instructions: `pollutantmean <- function(directory, pollutant, id = 1:332) {`
2225

26+
2327
####5) I get an error stating "unexpected '>' " or "unexpected '{' ".
2428

2529
You probably have an open `(` somewhere in your code. Double check it with a fine tooth comb to make sure you've closed all of your `()`, `{}`and `[]`.
2630

31+
2732
####6) My code seems to work but my answers don't match the sample output.
2833

2934
Are you taking the mean of the mean value for each file? That doesn't work mathematically. You need to combine all of the relevant data into a single data frame or vector and take the mean of *that*.
35+
36+
a <- c(1:5)
37+
b <- c(1:10)
38+
c <- c(10:15)
39+
40+
mean(c(a,b,c))
41+
[1] 6.904762
42+
43+
mean(c(mean(a),mean(b),mean(c)))
44+
[1] 7
45+
46+
You want the first approach, not the second.
47+
3048

3149
####7) My function seems to work when `id` is a single value but I get the following error message when it's something like `70:72`: "In pollutant1$ID == 1:332 : longer object length is not a multiple of shorter object length".
3250

@@ -47,12 +65,14 @@ Essentially, there are 2 options to solve this. The first is to not use a subse
4765

4866
The other alternative is to replace the `==` with `%in%`. In this case, the %in% operator will check each value of `id` against every value in the `ID` column, which is what you want. The downside to this approach is that it will probably be very, very slow if you've followed the tutorial example to create `pollutantmean()`.
4967

68+
5069
####8) How do I subset for either `nitrate` or `sulfate` when I calculate the mean?
5170

5271
If you wanted to subset nitrate, you would do that with `dat[, "nitrate"]`. Likewise you would use `dat[, "sulfate"]` for sulfate. When the function gets called you'll have something like: `pollutantmean(directory = "specdata", pollutant = "nitrate", id = 1:332)`.
5372

5473
So if you have either `pollutant = "nitrate"` or `pollutant = "sulfate"`, what would you put in place of `"sulfate"` and `"nitrate"` in subsetting examples above so that it would work in either case?
5574

75+
5676
####9) I'm subsetting my data frame using `dat$pollutant` but it doesn't seem to be working.
5777

5878
Recall from the lectures that $ makes R look for a literal name match. That's not what you want. You want to subset by the value of pollutant (either "sulfate" or "nitrate"), not by "pollutant" since you don't have a column by that name. So, you need to use brackets instead of $.

0 commit comments

Comments
 (0)