Reputation: 301
How do I use a data set in R which exists in a package that is not loaded? For example, if I want to use the melanoma data, which is in the MASS
package, and I write down melanoma
, it shows an error message: "Object 'melanoma' not found". If I write data("melanoma")
, ot shows
Warning Message: In data("melanoma"): data set 'melanoma' not found
How can I use this data set?
Upvotes: 0
Views: 167
Reputation: 226097
Use data(Melanoma, package="MASS")
Note that R is generally case-sensitive; I had to use help.search("melanoma")
(which does "fuzzy" rather than exact matching) to figure out that it's called "Melanoma", not "melanoma". (There's also a "melanoma" data set, which might be identical -- I haven't checked -- in the boot
package.)
As others have noted in comments you can also say Melanoma <- MASS::Melanoma
(you can assign the data to a different variable if you want, e.g. my_melanoma <- MASS::Melanoma
). Or you can just use MASS::Melanoma
directly in your code, although that will get unwieldy if you have to refer to it a lot.
Upvotes: 3