下载R语言和开发工具RStudio安装包 先安装R…
数据集的概念 数据集通常是由数据构成的一个矩形数组,行表示观测,列表示变量.表2-1提供了一个假想的病例数据集. 不同的行业对于数据集的行和列叫法不同.统计学家称它们为观测(observation)和变量 (variable),数据库分析师则称其为记录(record)和字段(field),数据挖掘和机器学习学科的研 究者则把它们叫作示例(example)和属性(attribute). 我们在R中使用术语:观测和变量.可以清楚地看到此数据集的结构(本例中是一个矩形数组)以及其中包含的内容和数据类型…
2.3.6 导入 SPSS 数据 IBM SPSS数据集可以通过foreign包中的函数read.spss()导入到R中,也可以使用Hmisc 包中的spss.get()函数.函数spss.get()是对read.spss()的一个封装,它可以为你自动设 置后者的许多参数,让整个转换过程更加简单一致,最后得到数据分析人员所期望的结果. 首先,下载并安装Hmisc包(foreign包已被默认安装): install.packages("Hmisc") 然后使用以下代码导入数据: libr…
R可从键盘.文本文件.Microsoft Excel和Access.流行的统计软件.特殊格 式的文件.多种关系型数据库管理系统.专业数据库.网站和在线服务中导入数据. 使用键盘了.有两种常见的方式:用R内置的文本编辑器和 直接在代码中嵌入数据.我们首先考虑文本编辑器. R中的函数edit()会自动调用一个允许手动输入数据的文本编辑器.具体步骤如下: (1) 创建一个空数据框(或矩阵),其中变量名和变量的模式需与理想中的最终数据集一致: (2) 针对这个数据对象调用文本编辑器,输入你的数据,并将结…
假设我们正在研究生理发育问 题,并收集了10名婴儿在出生后一年内的月龄和体重数据(见表1-).我们感兴趣的是体重的分 布及体重和月龄的关系. 可以使用函数c()以向量的形式输入月龄和体重数据,此函 数可将其参数组合成一个向量或列表.然后用mean().sd()和cor()函数分别获得体重的均值 和标准差,以及月龄和体重的相关度.最后使用plot()函数,从而用图形展示月龄和体重的关 系,这样就可以用可视化的方式检查其中可能存在的趋势.函数q()将结束会话并允许你退出R. age <- c(1,3…
1.基础数据结构 1.1 向量 # 创建向量a a <- c(1,2,3) print(a) 1.2 矩阵 #创建矩阵 mymat <- matrix(c(1:10), nrow=2, ncol=5, byrow=TRUE) #取第二行 mymat[2,] #取第二列 mymat[,2] #第一行第五列的元素 mymat[1,5] 1.3 数组 #创建数组 myarr <- array(c(1:12),dim=c(2,3,2)) print(myarr) #取矩阵或数组的维度 dim(m…
# ----------------------------------------------------# # R in Action (2nd ed): Chapter 3 # # Getting started with graphs # # requires that the Hmisc and RColorBrewer packages # # have been installed # # install.packages(c("Hmisc", "RColorB…
# ----------------------------------------------------# # R in Action (2nd ed): Chapter 3 # # Getting started with graphs # # requires that the Hmisc and RColorBrewer packages # # have been installed # # install.packages(c("Hmisc", "RColorB…
# ----------------------------------------------------# # R in Action (2nd ed): Chapter 3 # # Getting started with graphs # # requires that the Hmisc and RColorBrewer packages # # have been installed # # install.packages(c("Hmisc", "RColorB…
#---------------------------------------------------------------# # R in Action (2nd ed): Chapter 6 # # Basic graphs # # requires packages vcd, plotrix, sm, vioplot to be installed # # install.packages(c("vcd", "plotrix", "sm"…
#---------------------------------------------------------------# # R in Action (2nd ed): Chapter 6 # # Basic graphs # # requires packages vcd, plotrix, sm, vioplot to be installed # # install.packages(c("vcd", "plotrix", "sm"…
#---------------------------------------------------------------# # R in Action (2nd ed): Chapter 6 # # Basic graphs # # requires packages vcd, plotrix, sm, vioplot to be installed # # install.packages(c("vcd", "plotrix", "sm"…
#-----------------------------------# # R in Action (2nd ed): Chapter 5 # # Advanced data management # # requires that the reshape2 # # package has been installed # # install.packages("reshape2") # #-----------------------------------# # Class R…
#-----------------------------------# # R in Action (2nd ed): Chapter 5 # # Advanced data management # # requires that the reshape2 # # package has been installed # # install.packages("reshape2") # #-----------------------------------# # Class R…
#---------------------------------------------------------# # R in Action (2nd ed): Chapter 4 # # Basic data management # # requires that the reshape2 and sqldf packages have # # been installed # # install.packages(c('reshape2', 'sqldf')) # #--------…
#---------------------------------------------------------# # R in Action (2nd ed): Chapter 4 # # Basic data management # # requires that the reshape2 and sqldf packages have # # been installed # # install.packages(c('reshape2', 'sqldf')) # #--------…
#-------------------------------------------------------# # R in Action (2nd ed): Chapter 16 # # Cluster analysis # # requires packaged NbClust, flexclust, rattle # # install.packages(c("NbClust", "flexclust", "rattle")) # #-…
#-------------------------------------------------------# # R in Action (2nd ed): Chapter 16 # # Cluster analysis # # requires packaged NbClust, flexclust, rattle # # install.packages(c("NbClust", "flexclust", "rattle")) # #-…
#-----------------------------------------# # R in Action (2nd ed): Chapter 15 # # Time series # # requires forecast, tseries packages # # install.packages("forecast", "tseries") # #-----------------------------------------# par(ask=TR…
#-----------------------------------------# # R in Action (2nd ed): Chapter 15 # # Time series # # requires forecast, tseries packages # # install.packages("forecast", "tseries") # #-----------------------------------------# par(ask=TR…
#-----------------------------------------# # R in Action (2nd ed): Chapter 15 # # Time series # # requires forecast, tseries packages # # install.packages("forecast", "tseries") # #-----------------------------------------# par(ask=TR…
#-----------------------------------------# # R in Action (2nd ed): Chapter 15 # # Time series # # requires forecast, tseries packages # # install.packages("forecast", "tseries") # #-----------------------------------------# par(ask=TR…
#--------------------------------------------# # R in Action (2nd ed): Chapter 14 # # Principal components and factor analysis # # requires package psych # # install.packages("psych") # #--------------------------------------------# par(ask=TRUE…
#----------------------------------------------# # R in Action (2nd ed): Chapter 13 # # Generalized linear models # # requires packages AER, robust, gcc # # install.packages(c("AER", "robust", "gcc")) # #---------------------…
#----------------------------------------------# # R in Action (2nd ed): Chapter 13 # # Generalized linear models # # requires packages AER, robust, gcc # # install.packages(c("AER", "robust", "gcc")) # #---------------------…
#-------------------------------------------------------------------------# # R in Action (2nd ed): Chapter 12 # # Resampling statistics and bootstrapping # # requires packages coin, multcomp, vcd, MASS, lmPerm, boot # # install.packages(c("coin"…
#------------------------------------------------------------------------------------# # R in Action (2nd ed): Chapter 11 # # Intermediate graphs # # requires packages car, scatterplot3d, gclus, hexbin, IDPmisc, Hmisc, # # corrgram, vcd, rlg to be in…
#------------------------------------------------------------------------------------# # R in Action (2nd ed): Chapter 11 # # Intermediate graphs # # requires packages car, scatterplot3d, gclus, hexbin, IDPmisc, Hmisc, # # corrgram, vcd, rlg to be in…
#------------------------------------------------------------------------------------# # R in Action (2nd ed): Chapter 11 # # Intermediate graphs # # requires packages car, scatterplot3d, gclus, hexbin, IDPmisc, Hmisc, # # corrgram, vcd, rlg to be in…
#----------------------------------------# # R in Action (2nd ed): Chapter 10 # # Power analysis # # requires packages pwr to be installed # # install.packages("pwr") # #----------------------------------------# par(ask=TRUE) library(pwr) # t te…