Can't find the Dataset Boston in MASS


#1

I am trying to load Boston into the environment from package MASS. For some reason, it keeps telling me there's no such data. I have tried:

library(MASS)
data(Boston)

library(MASS)
boston <- Boston
dim(boston)

The result is NULL

I downloaded the newest version of R-studio.

Could anyone help me with this problem? Thank you.


#2

Weird works fine for me. Maybe trying reinstalling MASS?

library(MASS)
boston <- Boston
dim(boston)
#> [1] 506  14

Created on 2018-10-10 by the reprex package (v0.2.1)


#3

I have redownloaded it, but still not working.


#4

Well that's about the extent of my troubleshooting knowledge. For the sake of others, can you post the output of sessionInfo()


#5


#6

The data() function doesn't return a loaded object. It loads the objects into your environment, assigns it the predetermined name, and then returns a character vector of the name(s).

So Boston <- data(Boston) does the following:

  1. data(Boston) loads the dataset and assigns it to the Boston variable. Then it returns the vector "Boston".
  2. Boston <- ... takes that character vector and assigns it to the Boston variable, replacing the dataset with "Boston".

If you just use data(Boston) as it's own line, it'll work how you want.


#7

Both:
library(MASS)
Boston <- Boston
dim(Boston)

library(MASS)
Boston <- "Boston"
dim(Boston)

return to Null


#8

If dim(Boston) returns NULL, that means the Boston object already exists. Otherwise, you'd get an error. Because there's a local version, R uses that instead of looking into any attached packages.

Restart your R session (CTRL + SHIFT + F10) and try it again.


#9

Thank you so much for the help!