R如何匯入資料檔

  1. 使用內建資料,下例使用Anderson’s Iris data set (https://zh.wikipedia.org/wiki/%E5%AE%89%E5%BE%B7%E6%A3%AE%E9%B8%A2%E5%B0%BE%E8%8A%B1%E5%8D%89%E6%95%B0%E6%8D%AE%E9%9B%86)
data("iris") #將iris資料集載入Global Environment成為一個DataFrame
iris #列出iris資料集的所有欄位和每一筆資料
##     Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
## 1            5.1         3.5          1.4         0.2     setosa
## 2            4.9         3.0          1.4         0.2     setosa
## 3            4.7         3.2          1.3         0.2     setosa
## 4            4.6         3.1          1.5         0.2     setosa
## 5            5.0         3.6          1.4         0.2     setosa
## 6            5.4         3.9          1.7         0.4     setosa
## 7            4.6         3.4          1.4         0.3     setosa
## 8            5.0         3.4          1.5         0.2     setosa
## 9            4.4         2.9          1.4         0.2     setosa
## 10           4.9         3.1          1.5         0.1     setosa
## 11           5.4         3.7          1.5         0.2     setosa
## 12           4.8         3.4          1.6         0.2     setosa
## 13           4.8         3.0          1.4         0.1     setosa
## 14           4.3         3.0          1.1         0.1     setosa
## 15           5.8         4.0          1.2         0.2     setosa
## 16           5.7         4.4          1.5         0.4     setosa
## 17           5.4         3.9          1.3         0.4     setosa
## 18           5.1         3.5          1.4         0.3     setosa
## 19           5.7         3.8          1.7         0.3     setosa
## 20           5.1         3.8          1.5         0.3     setosa
## 21           5.4         3.4          1.7         0.2     setosa
## 22           5.1         3.7          1.5         0.4     setosa
## 23           4.6         3.6          1.0         0.2     setosa
## 24           5.1         3.3          1.7         0.5     setosa
## 25           4.8         3.4          1.9         0.2     setosa
## 26           5.0         3.0          1.6         0.2     setosa
## 27           5.0         3.4          1.6         0.4     setosa
## 28           5.2         3.5          1.5         0.2     setosa
## 29           5.2         3.4          1.4         0.2     setosa
## 30           4.7         3.2          1.6         0.2     setosa
## 31           4.8         3.1          1.6         0.2     setosa
## 32           5.4         3.4          1.5         0.4     setosa
## 33           5.2         4.1          1.5         0.1     setosa
## 34           5.5         4.2          1.4         0.2     setosa
## 35           4.9         3.1          1.5         0.2     setosa
## 36           5.0         3.2          1.2         0.2     setosa
## 37           5.5         3.5          1.3         0.2     setosa
## 38           4.9         3.6          1.4         0.1     setosa
## 39           4.4         3.0          1.3         0.2     setosa
## 40           5.1         3.4          1.5         0.2     setosa
## 41           5.0         3.5          1.3         0.3     setosa
## 42           4.5         2.3          1.3         0.3     setosa
## 43           4.4         3.2          1.3         0.2     setosa
## 44           5.0         3.5          1.6         0.6     setosa
## 45           5.1         3.8          1.9         0.4     setosa
## 46           4.8         3.0          1.4         0.3     setosa
## 47           5.1         3.8          1.6         0.2     setosa
## 48           4.6         3.2          1.4         0.2     setosa
## 49           5.3         3.7          1.5         0.2     setosa
## 50           5.0         3.3          1.4         0.2     setosa
## 51           7.0         3.2          4.7         1.4 versicolor
## 52           6.4         3.2          4.5         1.5 versicolor
## 53           6.9         3.1          4.9         1.5 versicolor
## 54           5.5         2.3          4.0         1.3 versicolor
## 55           6.5         2.8          4.6         1.5 versicolor
## 56           5.7         2.8          4.5         1.3 versicolor
## 57           6.3         3.3          4.7         1.6 versicolor
## 58           4.9         2.4          3.3         1.0 versicolor
## 59           6.6         2.9          4.6         1.3 versicolor
## 60           5.2         2.7          3.9         1.4 versicolor
## 61           5.0         2.0          3.5         1.0 versicolor
## 62           5.9         3.0          4.2         1.5 versicolor
## 63           6.0         2.2          4.0         1.0 versicolor
## 64           6.1         2.9          4.7         1.4 versicolor
## 65           5.6         2.9          3.6         1.3 versicolor
## 66           6.7         3.1          4.4         1.4 versicolor
## 67           5.6         3.0          4.5         1.5 versicolor
## 68           5.8         2.7          4.1         1.0 versicolor
## 69           6.2         2.2          4.5         1.5 versicolor
## 70           5.6         2.5          3.9         1.1 versicolor
## 71           5.9         3.2          4.8         1.8 versicolor
## 72           6.1         2.8          4.0         1.3 versicolor
## 73           6.3         2.5          4.9         1.5 versicolor
## 74           6.1         2.8          4.7         1.2 versicolor
## 75           6.4         2.9          4.3         1.3 versicolor
## 76           6.6         3.0          4.4         1.4 versicolor
## 77           6.8         2.8          4.8         1.4 versicolor
## 78           6.7         3.0          5.0         1.7 versicolor
## 79           6.0         2.9          4.5         1.5 versicolor
## 80           5.7         2.6          3.5         1.0 versicolor
## 81           5.5         2.4          3.8         1.1 versicolor
## 82           5.5         2.4          3.7         1.0 versicolor
## 83           5.8         2.7          3.9         1.2 versicolor
## 84           6.0         2.7          5.1         1.6 versicolor
## 85           5.4         3.0          4.5         1.5 versicolor
## 86           6.0         3.4          4.5         1.6 versicolor
## 87           6.7         3.1          4.7         1.5 versicolor
## 88           6.3         2.3          4.4         1.3 versicolor
## 89           5.6         3.0          4.1         1.3 versicolor
## 90           5.5         2.5          4.0         1.3 versicolor
## 91           5.5         2.6          4.4         1.2 versicolor
## 92           6.1         3.0          4.6         1.4 versicolor
## 93           5.8         2.6          4.0         1.2 versicolor
## 94           5.0         2.3          3.3         1.0 versicolor
## 95           5.6         2.7          4.2         1.3 versicolor
## 96           5.7         3.0          4.2         1.2 versicolor
## 97           5.7         2.9          4.2         1.3 versicolor
## 98           6.2         2.9          4.3         1.3 versicolor
## 99           5.1         2.5          3.0         1.1 versicolor
## 100          5.7         2.8          4.1         1.3 versicolor
## 101          6.3         3.3          6.0         2.5  virginica
## 102          5.8         2.7          5.1         1.9  virginica
## 103          7.1         3.0          5.9         2.1  virginica
## 104          6.3         2.9          5.6         1.8  virginica
## 105          6.5         3.0          5.8         2.2  virginica
## 106          7.6         3.0          6.6         2.1  virginica
## 107          4.9         2.5          4.5         1.7  virginica
## 108          7.3         2.9          6.3         1.8  virginica
## 109          6.7         2.5          5.8         1.8  virginica
## 110          7.2         3.6          6.1         2.5  virginica
## 111          6.5         3.2          5.1         2.0  virginica
## 112          6.4         2.7          5.3         1.9  virginica
## 113          6.8         3.0          5.5         2.1  virginica
## 114          5.7         2.5          5.0         2.0  virginica
## 115          5.8         2.8          5.1         2.4  virginica
## 116          6.4         3.2          5.3         2.3  virginica
## 117          6.5         3.0          5.5         1.8  virginica
## 118          7.7         3.8          6.7         2.2  virginica
## 119          7.7         2.6          6.9         2.3  virginica
## 120          6.0         2.2          5.0         1.5  virginica
## 121          6.9         3.2          5.7         2.3  virginica
## 122          5.6         2.8          4.9         2.0  virginica
## 123          7.7         2.8          6.7         2.0  virginica
## 124          6.3         2.7          4.9         1.8  virginica
## 125          6.7         3.3          5.7         2.1  virginica
## 126          7.2         3.2          6.0         1.8  virginica
## 127          6.2         2.8          4.8         1.8  virginica
## 128          6.1         3.0          4.9         1.8  virginica
## 129          6.4         2.8          5.6         2.1  virginica
## 130          7.2         3.0          5.8         1.6  virginica
## 131          7.4         2.8          6.1         1.9  virginica
## 132          7.9         3.8          6.4         2.0  virginica
## 133          6.4         2.8          5.6         2.2  virginica
## 134          6.3         2.8          5.1         1.5  virginica
## 135          6.1         2.6          5.6         1.4  virginica
## 136          7.7         3.0          6.1         2.3  virginica
## 137          6.3         3.4          5.6         2.4  virginica
## 138          6.4         3.1          5.5         1.8  virginica
## 139          6.0         3.0          4.8         1.8  virginica
## 140          6.9         3.1          5.4         2.1  virginica
## 141          6.7         3.1          5.6         2.4  virginica
## 142          6.9         3.1          5.1         2.3  virginica
## 143          5.8         2.7          5.1         1.9  virginica
## 144          6.8         3.2          5.9         2.3  virginica
## 145          6.7         3.3          5.7         2.5  virginica
## 146          6.7         3.0          5.2         2.3  virginica
## 147          6.3         2.5          5.0         1.9  virginica
## 148          6.5         3.0          5.2         2.0  virginica
## 149          6.2         3.4          5.4         2.3  virginica
## 150          5.9         3.0          5.1         1.8  virginica
  1. 匯入CSV
mydataset <- read.csv("c:/users/Wade/OneDrive/Statistics/RealEstate/A_lvr_land_A.csv", header = TRUE, sep = ",") #匯入台北市房地產時價登錄的CSV檔,並置入名為mydataset的dataframe中
  1. 匯入SPSS (.sav)(read.spss函式不支援中文,如果遇到.sav檔中有中文則必須要從SPSS中匯出成CSV後再從R把CSV匯入)
#install.packages("foreign") #如果之前沒有安裝過,要先安裝foreign套件
require(foreign) #載入foreign套件
## Loading required package: foreign
mydataset <- read.spss("c:/users/Wade/OneDrive/Statistics/基礎統計分析/SPSS_SAV/3.2.sav") #使用foreign套件中的read.spss函式讀取侯老師提供的3.2.sav資料檔
  1. 匯入Excel (.xlsx)(read.xlsx的效能不好,建議從Excel先轉成CSV後再匯入R)
#install.packages("xlsx") #如果之前沒有安裝過,要先安裝xlsx套件
require(xlsx) #載入xlsx套件
## Loading required package: xlsx
## Loading required package: rJava
## Loading required package: xlsxjars
mydataset <- read.xlsx("c:/users/Wade/OneDrive/Statistics/MSFT.xlsx", sheetIndex = 1) #使用xlsx套件中的read.xlsx函式讀取Excel檔案中的第一個工作表

使用R內建的資料集

data(package="ggplot2")

從上面可以看出ggplot2套件內建了以上8個datasets。

data()
data(package = .packages(all.available = TRUE))
## Warning in data(package = .packages(all.available = TRUE)): datasets have
## been moved from package 'base' to package 'datasets'
## Warning in data(package = .packages(all.available = TRUE)): datasets have
## been moved from package 'stats' to package 'datasets'
結果如下:
Data sets in package !¥boot!|:

acme                                               Monthly Excess Returns
aids                                               Delay in AIDS Reporting in England and Wales
aircondit                                          Failures of Air-conditioning Equipment
aircondit7                                         Failures of Air-conditioning Equipment
amis                                               Car Speeding and Warning Signs
aml                                                Remission Times for Acute Myelogenous Leukaemia
beaver                                             Beaver Body Temperature Data
bigcity                                            Population of U.S. Cities
brambles                                           Spatial Location of Bramble Canes
breslow                                            Smoking Deaths Among Doctors
calcium                                            Calcium Uptake Data
cane                                               Sugar-cane Disease Data
capability                                         Simulated Manufacturing Process Data
catsM                                              Weight Data for Domestic Cats
cav                                                Position of Muscle Caveolae
cd4                                                CD4 Counts for HIV-Positive Patients
cd4.nested                                         Nested Bootstrap of cd4 data
channing                                           Channing House Data
city                                               Population of U.S. Cities
claridge                                           Genetic Links to Left-handedness
cloth                                              Number of Flaws in Cloth
co.transfer                                        Carbon Monoxide Transfer
coal                                               Dates of Coal Mining Disasters
darwin                                             Darwin's Plant Height Differences
dogs                                               Cardiac Data for Domestic Dogs
downs.bc                                           Incidence of Down's Syndrome in British Columbia
ducks                                              Behavioral and Plumage Characteristics of Hybrid Ducks
fir                                                Counts of Balsam-fir Seedlings
frets                                              Head Dimensions in Brothers
grav                                               Acceleration Due to Gravity
gravity                                            Acceleration Due to Gravity
hirose                                             Failure Time of PET Film
islay                                              Jura Quartzite Azimuths on Islay
manaus                                             Average Heights of the Rio Negro river at Manaus
melanoma                                           Survival from Malignant Melanoma
motor                                              Data from a Simulated Motorcycle Accident
neuro                                              Neurophysiological Point Process Data
nitrofen                                           Toxicity of Nitrofen in Aquatic Systems
nodal                                              Nodal Involvement in Prostate Cancer
nuclear                                            Nuclear Power Station Construction Data
paulsen                                            Neurotransmission in Guinea Pig Brains
poisons                                            Animal Survival Times
polar                                              Pole Positions of New Caledonian Laterites
remission                                          Cancer Remission and Cell Activity
salinity                                           Water Salinity and River Discharge
survival                                           Survival of Rats after Radiation Doses
tau                                                Tau Particle Decay Modes
tuna                                               Tuna Sighting Data
urine                                              Urine Analysis Data
wool                                               Australian Relative Wool Prices

Data sets in package !¥cluster!|:

agriculture                                        European Union Agricultural Workforces
animals                                            Attributes of Animals
chorSub                                            Subset of C-horizon of Kola Data
flower                                             Flower Characteristics
plantTraits                                        Plant Species Traits Data
pluton                                             Isotopic Composition Plutonium Batches
ruspini                                            Ruspini Data
votes.repub                                        Votes for Republican Candidate in Presidential Elections
xclara                                             Bivariate Data Set with 3 Clusters

Data sets in package !¥colorspace!|:

USSouthPolygon                                     Polygon for County Map of US South States: Alabama, Georgia, and South Carolina

Data sets in package !¥datasets!|:

AirPassengers                                      Monthly Airline Passenger Numbers 1949-1960
BJsales                                            Sales Data with Leading Indicator
BJsales.lead (BJsales)                             Sales Data with Leading Indicator
BOD                                                Biochemical Oxygen Demand
CO2                                                Carbon Dioxide Uptake in Grass Plants
ChickWeight                                        Weight versus age of chicks on different diets
DNase                                              Elisa assay of DNase
EuStockMarkets                                     Daily Closing Prices of Major European Stock Indices, 1991-1998
Formaldehyde                                       Determination of Formaldehyde
HairEyeColor                                       Hair and Eye Color of Statistics Students
Harman23.cor                                       Harman Example 2.3
Harman74.cor                                       Harman Example 7.4
Indometh                                           Pharmacokinetics of Indomethacin
InsectSprays                                       Effectiveness of Insect Sprays
JohnsonJohnson                                     Quarterly Earnings per Johnson & Johnson Share
LakeHuron                                          Level of Lake Huron 1875-1972
LifeCycleSavings                                   Intercountry Life-Cycle Savings Data
Loblolly                                           Growth of Loblolly pine trees
Nile                                               Flow of the River Nile
Orange                                             Growth of Orange Trees
OrchardSprays                                      Potency of Orchard Sprays
PlantGrowth                                        Results from an Experiment on Plant Growth
Puromycin                                          Reaction Velocity of an Enzymatic Reaction
Seatbelts                                          Road Casualties in Great Britain 1969-84
Theoph                                             Pharmacokinetics of Theophylline
Titanic                                            Survival of passengers on the Titanic
ToothGrowth                                        The Effect of Vitamin C on Tooth Growth in Guinea Pigs
UCBAdmissions                                      Student Admissions at UC Berkeley
UKDriverDeaths                                     Road Casualties in Great Britain 1969-84
UKgas                                              UK Quarterly Gas Consumption
USAccDeaths                                        Accidental Deaths in the US 1973-1978
USArrests                                          Violent Crime Rates by US State
USJudgeRatings                                     Lawyers' Ratings of State Judges in the US Superior Court
USPersonalExpenditure                              Personal Expenditure Data
UScitiesD                                          Distances Between European Cities and Between US Cities
VADeaths                                           Death Rates in Virginia (1940)
WWWusage                                           Internet Usage per Minute
WorldPhones                                        The World's Telephones
ability.cov                                        Ability and Intelligence Tests
airmiles                                           Passenger Miles on Commercial US Airlines, 1937-1960
airquality                                         New York Air Quality Measurements
anscombe                                           Anscombe's Quartet of 'Identical' Simple Linear Regressions
attenu                                             The Joyner-Boore Attenuation Data
attitude                                           The Chatterjee-Price Attitude Data
austres                                            Quarterly Time Series of the Number of Australian Residents
beaver1 (beavers)                                  Body Temperature Series of Two Beavers
beaver2 (beavers)                                  Body Temperature Series of Two Beavers
cars                                               Speed and Stopping Distances of Cars
chickwts                                           Chicken Weights by Feed Type
co2                                                Mauna Loa Atmospheric CO2 Concentration
crimtab                                            Student's 3000 Criminals Data
discoveries                                        Yearly Numbers of Important Discoveries
esoph                                              Smoking, Alcohol and (O)esophageal Cancer
euro                                               Conversion Rates of Euro Currencies
euro.cross (euro)                                  Conversion Rates of Euro Currencies
eurodist                                           Distances Between European Cities and Between US Cities
faithful                                           Old Faithful Geyser Data
fdeaths (UKLungDeaths)                             Monthly Deaths from Lung Diseases in the UK
freeny                                             Freeny's Revenue Data
freeny.x (freeny)                                  Freeny's Revenue Data
freeny.y (freeny)                                  Freeny's Revenue Data
infert                                             Infertility after Spontaneous and Induced Abortion
iris                                               Edgar Anderson's Iris Data
iris3                                              Edgar Anderson's Iris Data
islands                                            Areas of the World's Major Landmasses
ldeaths (UKLungDeaths)                             Monthly Deaths from Lung Diseases in the UK
lh                                                 Luteinizing Hormone in Blood Samples
longley                                            Longley's Economic Regression Data
lynx                                               Annual Canadian Lynx trappings 1821-1934
mdeaths (UKLungDeaths)                             Monthly Deaths from Lung Diseases in the UK
morley                                             Michelson Speed of Light Data
mtcars                                             Motor Trend Car Road Tests
nhtemp                                             Average Yearly Temperatures in New Haven
nottem                                             Average Monthly Temperatures at Nottingham, 1920-1939
npk                                                Classical N, P, K Factorial Experiment
occupationalStatus                                 Occupational Status of Fathers and their Sons
precip                                             Annual Precipitation in US Cities
presidents                                         Quarterly Approval Ratings of US Presidents
pressure                                           Vapor Pressure of Mercury as a Function of Temperature
quakes                                             Locations of Earthquakes off Fiji
randu                                              Random Numbers from Congruential Generator RANDU
rivers                                             Lengths of Major North American Rivers
rock                                               Measurements on Petroleum Rock Samples
sleep                                              Student's Sleep Data
stack.loss (stackloss)                             Brownlee's Stack Loss Plant Data
stack.x (stackloss)                                Brownlee's Stack Loss Plant Data
stackloss                                          Brownlee's Stack Loss Plant Data
state.abb (state)                                  US State Facts and Figures
state.area (state)                                 US State Facts and Figures
state.center (state)                               US State Facts and Figures
state.division (state)                             US State Facts and Figures
state.name (state)                                 US State Facts and Figures
state.region (state)                               US State Facts and Figures
state.x77 (state)                                  US State Facts and Figures
sunspot.month                                      Monthly Sunspot Data, from 1749 to "Present"
sunspot.year                                       Yearly Sunspot Data, 1700-1988
sunspots                                           Monthly Sunspot Numbers, 1749-1983
swiss                                              Swiss Fertility and Socioeconomic Indicators (1888) Data
treering                                           Yearly Treering Data, -6000-1979
trees                                              Girth, Height and Volume for Black Cherry Trees
uspop                                              Populations Recorded by the US Census
volcano                                            Topographic Information on Auckland's Maunga Whau Volcano
warpbreaks                                         The Number of Breaks in Yarn during Weaving
women                                              Average Heights and Weights for American Women

Data sets in package !¥dichromat!|:

dalton                                             Effects of Daltonism (Red-Green Color Blindness)
dalton.colors (dalton)                             Effects of Daltonism (Red-Green Color Blindness)

Data sets in package !¥earth!|:

etitanic                                           Titanic data with incomplete cases removed
ozone1                                             Ozone readings in Los Angeles with incomplete cases removed

Data sets in package !¥ggplot2!|:

diamonds                                           Prices of 50,000 round cut diamonds
economics                                          US economic time series.
midwest                                            Midwest demographics.
movies                                             Movie information and user ratings from IMDB.com.
mpg                                                Fuel economy data from 1999 and 2008 for 38 popular models of car
msleep                                             An updated and expanded version of the mammals sleep dataset.
presidential                                       Terms of 10 presidents from Eisenhower to Bush W.
seals                                              Vector field of seal movements.

Data sets in package !¥lattice!|:

barley                                             Yield data from a Minnesota barley trial
environmental                                      Atmospheric environmental conditions in New York City
ethanol                                            Engine exhaust fumes from burning ethanol
melanoma                                           Melanoma skin cancer incidence
singer                                             Heights of New York Choral Society singers

Data sets in package !¥MASS!|:

Aids2                                              Australian AIDS Survival Data
Animals                                            Brain and Body Weights for 28 Species
Boston                                             Housing Values in Suburbs of Boston
Cars93                                             Data from 93 Cars on Sale in the USA in 1993
Cushings                                           Diagnostic Tests on Patients with Cushing's Syndrome
DDT                                                DDT in Kale
GAGurine                                           Level of GAG in Urine of Children
Insurance                                          Numbers of Car Insurance claims
Melanoma                                           Survival from Malignant Melanoma
OME                                                Tests of Auditory Perception in Children with OME
Pima.te                                            Diabetes in Pima Indian Women
Pima.tr                                            Diabetes in Pima Indian Women
Pima.tr2                                           Diabetes in Pima Indian Women
Rabbit                                             Blood Pressure in Rabbits
Rubber                                             Accelerated Testing of Tyre Rubber
SP500                                              Returns of the Standard and Poors 500
Sitka                                              Growth Curves for Sitka Spruce Trees in 1988
Sitka89                                            Growth Curves for Sitka Spruce Trees in 1989
Skye                                               AFM Compositions of Aphyric Skye Lavas
Traffic                                            Effect of Swedish Speed Limits on Accidents
UScereal                                           Nutritional and Marketing Information on US Cereals
UScrime                                            The Effect of Punishment Regimes on Crime Rates
VA                                                 Veteran's Administration Lung Cancer Trial
abbey                                              Determinations of Nickel Content
accdeaths                                          Accidental Deaths in the US 1973-1978
anorexia                                           Anorexia Data on Weight Change
bacteria                                           Presence of Bacteria after Drug Treatments
beav1                                              Body Temperature Series of Beaver 1
beav2                                              Body Temperature Series of Beaver 2
biopsy                                             Biopsy Data on Breast Cancer Patients
birthwt                                            Risk Factors Associated with Low Infant Birth Weight
cabbages                                           Data from a cabbage field trial
caith                                              Colours of Eyes and Hair of People in Caithness
cats                                               Anatomical Data from Domestic Cats
cement                                             Heat Evolved by Setting Cements
chem                                               Copper in Wholemeal Flour
coop                                               Co-operative Trial in Analytical Chemistry
cpus                                               Performance of Computer CPUs
crabs                                              Morphological Measurements on Leptograpsus Crabs
deaths                                             Monthly Deaths from Lung Diseases in the UK
drivers                                            Deaths of Car Drivers in Great Britain 1969-84
eagles                                             Foraging Ecology of Bald Eagles
epil                                               Seizure Counts for Epileptics
farms                                              Ecological Factors in Farm Management
fgl                                                Measurements of Forensic Glass Fragments
forbes                                             Forbes' Data on Boiling Points in the Alps
galaxies                                           Velocities for 82 Galaxies
gehan                                              Remission Times of Leukaemia Patients
genotype                                           Rat Genotype Data
geyser                                             Old Faithful Geyser Data
gilgais                                            Line Transect of Soil in Gilgai Territory
hills                                              Record Times in Scottish Hill Races
housing                                            Frequency Table from a Copenhagen Housing Conditions Survey
immer                                              Yields from a Barley Field Trial
leuk                                               Survival Times and White Blood Counts for Leukaemia Patients
mammals                                            Brain and Body Weights for 62 Species of Land Mammals
mcycle                                             Data from a Simulated Motorcycle Accident
menarche                                           Age of Menarche in Warsaw
michelson                                          Michelson's Speed of Light Data
minn38                                             Minnesota High School Graduates of 1938
motors                                             Accelerated Life Testing of Motorettes
muscle                                             Effect of Calcium Chloride on Muscle Contraction in Rat Hearts
newcomb                                            Newcomb's Measurements of the Passage Time of Light
nlschools                                          Eighth-Grade Pupils in the Netherlands
npk                                                Classical N, P, K Factorial Experiment
npr1                                               US Naval Petroleum Reserve No. 1 data
oats                                               Data from an Oats Field Trial
painters                                           The Painter's Data of de Piles
petrol                                             N. L. Prater's Petrol Refinery Data
phones                                             Belgium Phone Calls 1950-1973
quine                                              Absenteeism from School in Rural New South Wales
road                                               Road Accident Deaths in US States
rotifer                                            Numbers of Rotifers by Fluid Density
ships                                              Ships Damage Data
shoes                                              Shoe wear data of Box, Hunter and Hunter
shrimp                                             Percentage of Shrimp in Shrimp Cocktail
shuttle                                            Space Shuttle Autolander Problem
snails                                             Snail Mortality Data
steam                                              The Saturated Steam Pressure Data
stormer                                            The Stormer Viscometer Data
survey                                             Student Survey Data
synth.te                                           Synthetic Classification Problem
synth.tr                                           Synthetic Classification Problem
topo                                               Spatial Topographic Data
waders                                             Counts of Waders at 15 Sites in South Africa
whiteside                                          House Insulation: Whiteside's Data
wtloss                                             Weight Loss Data from an Obese Patient

Data sets in package !¥Matrix!|:

CAex                                               Albers' example Matrix with "Difficult" Eigen Factorization
KNex                                               Koenker-Ng Example Sparse Model Matrix and Response Vector
USCounties                                         USCounties Contiguity Matrix

Data sets in package !¥mgcv!|:

columb                                             Reduced version of Columbus OH crime data
columb.polys                                       Reduced version of Columbus OH crime data

Data sets in package !¥nlme!|:

Alfalfa                                            Split-Plot Experiment on Varieties of Alfalfa
Assay                                              Bioassay on Cell Culture Plate
BodyWeight                                         Rat weight over time for different diets
Cefamandole                                        Pharmacokinetics of Cefamandole
Dialyzer                                           High-Flux Hemodialyzer
Earthquake                                         Earthquake Intensity
Fatigue                                            Cracks caused by metal fatigue
Gasoline                                           Refinery yield of gasoline
Glucose                                            Glucose levels over time
Glucose2                                           Glucose Levels Following Alcohol Ingestion
Gun                                                Methods for firing naval guns
IGF                                                Radioimmunoassay of IGF-I Protein
Machines                                           Productivity Scores for Machines and Workers
MathAchSchool                                      School demographic data for MathAchieve
MathAchieve                                        Mathematics achievement scores
Meat                                               Tenderness of meat
Milk                                               Protein content of cows' milk
Muscle                                             Contraction of heart muscle sections
Nitrendipene                                       Assay of nitrendipene
Oats                                               Split-plot Experiment on Varieties of Oats
Orthodont                                          Growth curve data on an orthdontic measurement
Ovary                                              Counts of Ovarian Follicles
Oxboys                                             Heights of Boys in Oxford
Oxide                                              Variability in Semiconductor Manufacturing
PBG                                                Effect of Phenylbiguanide on Blood Pressure
Phenobarb                                          Phenobarbitol Kinetics
Pixel                                              X-ray pixel intensities over time
Quinidine                                          Quinidine Kinetics
Rail                                               Evaluation of Stress in Railway Rails
RatPupWeight                                       The weight of rat pups
Relaxin                                            Assay for Relaxin
Remifentanil                                       Pharmacokinetics of remifentanil
Soybean                                            Growth of soybean plants
Spruce                                             Growth of Spruce Trees
Tetracycline1                                      Pharmacokinetics of tetracycline
Tetracycline2                                      Pharmacokinetics of tetracycline
Wafer                                              Modeling of Analog MOS Circuits
Wheat                                              Yields by growing conditions
Wheat2                                             Wheat Yield Trials
bdf                                                Language scores
ergoStool                                          Ergometrics experiment with stool types

Data sets in package !¥plotrix!|:

death_reg                                          Death registrations from 1996 to 2010
soils                                              Soil texture data from 125 soils

Data sets in package !¥plyr!|:

baseball                                           Yearly batting records for all major league baseball players
ozone                                              Monthly ozone measurements over Central America.

Data sets in package !¥RCurl!|:

mimeTypeExtensions                                 Mapping from extension to MIME type

Data sets in package !¥reshape2!|:

french_fries                                       Sensory data from a french fries experiment.
smiths                                             Demo data describing the Smiths.
tips                                               Tipping data

Data sets in package !¥rpart!|:

car.test.frame                                     Automobile Data from 'Consumer Reports' 1990
car90                                              Automobile Data from 'Consumer Reports' 1990
cu.summary                                         Automobile Data from 'Consumer Reports' 1990
kyphosis                                           Data on Children who have had Corrective Spinal Surgery
solder                                             Soldering of Components on Printed-Circuit Boards
stagec                                             Stage C Prostate Cancer

Data sets in package !¥survival!|:

aml (leukemia)                                     Acute Myelogenous Leukemia survival data
bladder                                            Bladder Cancer Recurrences
bladder1 (bladder)                                 Bladder Cancer Recurrences
bladder2 (bladder)                                 Bladder Cancer Recurrences
cancer                                             NCCTG Lung Cancer Data
cgd                                                Chronic Granulotomous Disease data
cgd0 (cgd)                                         Chronic Granulotomous Disease data
colon                                              Chemotherapy for Stage B/C colon cancer
flchain                                            Assay of serum free light chain for 7874 subjects.
heart                                              Stanford Heart Transplant data
jasa (heart)                                       Stanford Heart Transplant data
jasa1 (heart)                                      Stanford Heart Transplant data
kidney                                             Kidney catheter data
leukemia                                           Acute Myelogenous Leukemia survival data
logan                                              Data from the 1972-78 GSS data used by Logan
lung                                               NCCTG Lung Cancer Data
mgus                                               Monoclonal gammapothy data
mgus1 (mgus)                                       Monoclonal gammapothy data
mgus2                                              Monoclonal gammapothy data
nwtco                                              Data from the National Wilm's Tumor Study
ovarian                                            Ovarian Cancer Survival Data
pbc                                                Mayo Clinic Primary Biliary Cirrhosis Data
pbcseq (pbc)                                       Mayo Clinic Primary Biliary Cirrhosis, sequential data
rats                                               Rat treatment data from Mantel et al
rats2 (rats)                                       Rat data from Gail et al.
stanford2                                          More Stanford Heart Transplant data
survexp.mn (survexp)                               Census Data Sets for the Expected Survival and Person Years Functions
survexp.us (survexp)                               Census Data Sets for the Expected Survival and Person Years Functions
survexp.usr (survexp)                              Census Data Sets for the Expected Survival and Person Years Functions
tobin                                              Tobin's Tobit data
transplant                                         Liver transplant waiting list
uspop2                                             Projected US Population
veteran                                            Veterans' Administration Lung Cancer study

Data sets in package !¥TeachingDemos!|:

USCrimes                                           US Crime Statistics
ccc (gps)                                          Sample data downloaded and converted from a GPS unit
coin.faces                                         Designs for coin faces for use with plot.rgl.coin
evap                                               Data on soil evaporation.
h2h (gps)                                          Sample data downloaded and converted from a GPS unit
ldsgrowth                                          Growth of The Church of Jesus Christ of Latter-day Saints.
outliers                                           Outliers data
stork                                              Neyman's Stork data
towork (gps)                                       Sample data downloaded and converted from a GPS unit

Data sets in package !¥xtable!|:

tli                                                Math scores from Texas Assessment of Academic Skills (TAAS)
plot(AirPassengers)

上圖就是1949~1960每個月搭飛機的人數

R如何匯出資料檔

  1. 匯出CSV檔案
x <- data.frame(日期 = Sys.Date(), 抽出順序 = 1:6 , 本期大樂透明牌 = sample(1:49, 6, FALSE)) #將三個變數「日期」、「抽出順序」、「本期大樂透明牌」放到名為X的Data Frame中
write.csv(x, "d:/lotto.csv", row.names = FALSE, col.names = TRUE)
## Warning in write.csv(x, "d:/lotto.csv", row.names = FALSE, col.names =
## TRUE): attempt to set 'col.names' ignored

R如何儲存/載入RData

  1. 將R物件儲存成.RData檔案:
save(iris, file = "d:/iris.RData")
  1. 載入.RData檔案:
load("d:/iris.Rdata")