补充练习题
head(mtcars)
#先根据气缸数正排序,再根据里程数逆排序
ordermtcars <- mtcars[order(mtcars$cyl,-mtcars$mpg),]
head(ordermtcars)
#用RODBC包从mangoTraining中连接外部数据Northwind.mdb文件中提取“Employees”,和“Orders"表格,合并
#这个找不到= =
library(mangoTraining)
if (!require(RODBC)) install.packages("RODBC")
library(RODBC)
system.file(package = "mangoTraining","extdata/NorthWind.mdb")
#使用reshape2包里面的tips数据计算性别和抽烟分类后给小费的平均值
library(reshape2)
objects("package:reshape2")
tips <- reshape2::tips
head(tips)
nTips <- melt(tips,c("sex","smoker"),"tip")
head(nTips)
tipsMean <- dcast(nTips,.~sex+smoker,mean)
head(tipsMean)
#把djData中的Data列分为3个新列Month、Day、Year,确保不影响原始的Data
djData <- mangoTraining::dow_jones_data
library(lubridate)
head(djData)
djData$nDate <- as.character(djData$Date)
year<-strsplit(djData$nDate,split = "/")
year <- t(as.data.frame(year))
djData <- cbind(djData,year,row.names = rownames(djData))
colnames(djData)[c(9,10,11)] <- c("month","date","year")
head(djData)
一千个哈姆雷特,每道题都有不同的做法,做不出来就算了。
书已经看了一大半了,思维貌似还没有跟上,多练习。