Because I am totally not a programming or a statistics person, I started to do the Coursera course on R. I have access to RStudio cloudversion. One of the assignments talks about the logical operators, i.e., AND.
The steps I took:
L1. og in to your Posit Cloud account and open an existing RStudio project or create a new project.
2. Select the Packages tab in the Output pane.
3. Select the datasets box in the System Library list of packages. (Here I noticed I have version 4.5.1. whereas their screenshot shows 4.3.1)
4. Run the following command data("airquality") in the console to load the airquality dataset.
5. Then, run the command View(airquality) to open the dataset in the Script Editor.
(This dataset is a data frame with six columns: Ozone (the ozone measurement), Solar.R (the solar measurement), Wind (the wind measurement), Temp (the temperature in Fahrenheit), and the Month and Day these measurements were taken. Each row represents a specific month and day combination.)
Then according to the screenshot of the course material, typing the logical statement airquality[, "Solar.R"] > 150 & airquality[, "Wind"] > 10 into the console should give the selection of rows where this is applicable.
What am I doing wrong (and please be patient with me because these are the little things that have kept me from wanting to learn something like R for a long time).
You are not doing anything wrong. What your code produces is a vector of logical values, one per row of the airquality data frame, signalling whether each row satisfies your conditions (true) or not (false). If you want to get the indices of the qualifying rows, you can use which(airquality[, "Solar.R"] > 150 & airquality[, "Wind"] > 10). If you want to see the rows themselves, you can use airquality[airquality[, "Solar.R"] > 150 & airquality[, "Wind"] > 10, ].
Thanks for your reply. Using your codes I was able to see the different values as mentioned in the course. Which leaves me wondering why so often with computer programming, those who set up the course (or write the manual) assume the learner possesses some knowledge, which obviously isn't there...
Could you share that screenshot?
My guess is you might be running just a partial expression, or there may be some confusion about the context.
Was the relevant code perhaps formatted across multiple lines, for example:
> airquality[
+ airquality[, "Solar.R"] > 150 & airquality[, "Wind"] > 10
+ ,
+ ]
Ozone Solar.R Wind Temp Month Day
4 18 313 11.5 62 5 4
NA NA NA NA NA NA NA
NA.1 NA NA NA NA NA NA
14 14 274 10.9 68 5 14
...
Or maybe they created a logical vector that was used later for subsetting:
> x <- airquality[, "Solar.R"] > 150 & airquality[, "Wind"] > 10
> airquality[x, ]
Ozone Solar.R Wind Temp Month Day
4 18 313 11.5 62 5 4
NA NA NA NA NA NA NA
NA.1 NA NA NA NA NA NA
14 14 274 10.9 68 5 14
...
This code specifies that R should return a value of TRUE for rows in which the airquality dataset’s Solar.R value is greater than 150 and its Wind value is greater than 10, and a value of FALSE otherwise.
Only the rows where both of these conditions are true fulfill the criteria, such as the following row:
Perhaps wording could be improved here, especially for material that's targeting people who could be new to R and data and perhaps to technical material in general. And there's a chance it's not from a native speaker, so emphasises and focus could feel bit off as we [non-native speakers] sometimes tend to carry over our native sentence structure, something that a good editor should spot and correct before publishing.
Though I wouldn't consider it wrong either: screenshot is not claimed to be the result of said logical statement, instead it's a (somewhat lazy) illustration describing a woud-be subset; and you do get TRUE / FALSE values as promised ("/../ R should return a value of TRUE /../ and a value of FALSE /../").
Maybe following some more established titles would provide more polished learning experience, you can then go though courses for certificates and slightly alternative approaches.
There are too many to list, just some to check:
Both have reached a 2nd edition, and both also refer to more beginner-friendly optional extra material if needed.
If you'd rather start by building a stronger base with base R before jumping into Tidyverse :