Dr. Spock
Dr. Spock

Reputation: 11

how to load dataset package

I downloaded the dataset package but not sure how to load it. I know how to read csv files but not sure how to read the data. http://www.inside-r.org/r-doc/datasets/state.division

I have to use state.division. Thanks

Upvotes: 1

Views: 3445

Answers (1)

C8H10N4O2
C8H10N4O2

Reputation: 19025

Welcome to StackOverflow and R. First I would start with:

> library(help = "datasets")

This tells you a little about the available datasets in this package.

This package is part of the base R installation, and you don't need to load it. If you're curious where these datasets are stored on your machine, you can enter:

> system.file("data",package = "datasets")

For more info on the state datasets, you can enter: ?state This tells you that state.division is one of the datasets available in this package.

> str(state.division)

However, it won't make a lot of sense without some additional context, so try something like:

> head(df <- data.frame(state.abb, state.division, state.x77))

           state.abb     state.division Population Income Illiteracy Life.Exp Murder HS.Grad
Alabama           AL East South Central       3615   3624        2.1    69.05   15.1    41.3
Alaska            AK            Pacific        365   6315        1.5    69.31   11.3    66.7
Arizona           AZ           Mountain       2212   4530        1.8    70.55    7.8    58.1
Arkansas          AR West South Central       2110   3378        1.9    70.66   10.1    39.9
California        CA            Pacific      21198   5114        1.1    71.71   10.3    62.6
Colorado          CO           Mountain       2541   4884        0.7    72.06    6.8    63.9
           Frost   Area
Alabama       20  50708
Alaska       152 566432
Arizona       15 113417
Arkansas      65  51945
California    20 156361
Colorado     166 103766

With a data.frame you should have the context you need to start make interesting plots or models, for example a linear regression model:

summary(lm(Murder ~ state.division + Illiteracy, data=df, weights=Population))

Upvotes: 3

Related Questions