r-intro-geospatial icon indicating copy to clipboard operation
r-intro-geospatial copied to clipboard

Always use comma notation for subsetting data frame columns

Open jsta opened this issue 5 years ago • 1 comments
trafficstars

Lines L315:L325 in Lesson 5 advocate for subsetting columns without comma notation:

head(gapminder[3])

I'd argue that for clarity sake, we should change this to always use comma notation:

head(gapminder[,3]

See #86

jsta avatar Sep 23 '20 13:09 jsta

I disagree with this suggestion because the objects returned by each operation are different:

> class(gapminder[3]) == class(gapminder[ ,3])
[1] FALSE
>
> mode(gapminder[3]) == mode(gapminder[ ,3])
[1] FALSE
>
> typeof(gapminder[3]) == typeof(gapminder[ ,3])
[1] FALSE

However, both objects contain the same values:

> all(gapminder[3] == gapminder[ ,3])
[1] TRUE

For beginners, or even experts, this subtle change could go unnoticed and produce unexpected consequences.

For that reason, I think it's better to close this issue without implementing the suggested changes.

albhasan avatar Jan 21 '24 00:01 albhasan