title: “Question on R variables” output: html_document

#aggregate function with the variable "diamonds"

diamonds <- read.csv(url('http://vincentarelbundock.github.io/Rdatasets/csv/Ecdat/Diamond.csv'))
data("diamonds", package = "ggplot2")
head(diamonds)
##   carat       cut color clarity depth table price    x    y    z
## 1  0.23     Ideal     E     SI2  61.5    55   326 3.95 3.98 2.43
## 2  0.21   Premium     E     SI1  59.8    61   326 3.89 3.84 2.31
## 3  0.23      Good     E     VS1  56.9    65   327 4.05 4.07 2.31
## 4  0.29   Premium     I     VS2  62.4    58   334 4.20 4.23 2.63
## 5  0.31      Good     J     SI2  63.3    58   335 4.34 4.35 2.75
## 6  0.24 Very Good     J    VVS2  62.8    57   336 3.94 3.96 2.48
aggregate(price ~ cut ,diamonds, mean)
##         cut    price
## 1      Fair 4358.758
## 2      Good 3928.864
## 3 Very Good 3981.760
## 4   Premium 4584.258
## 5     Ideal 3457.542
# I use the same code as above but change the variable name to "theurl. This time I get different result set. I get less columns. Some of the columns like cut is missing from my results.

theurl <- read.csv(url('http://vincentarelbundock.github.io/Rdatasets/csv/Ecdat/Diamond.csv'))
data("theurl", package = "ggplot2")
## Warning in data("theurl", package = "ggplot2"): data set 'theurl' not found
head(theurl)
##   X carat colour clarity certification price
## 1 1  0.30      D     VS2           GIA  1302
## 2 2  0.30      E     VS1           GIA  1510
## 3 3  0.30      G    VVS1           GIA  1510
## 4 4  0.30      G     VS1           GIA  1260
## 5 5  0.31      D     VS1           GIA  1641
## 6 6  0.31      E     VS1           GIA  1555
#aggregate(price ~ cut ,theurl, mean) # the aggregate function does not work with any variable name other than "diamonds"