## ----风格,echo = false,结果='Asis'-----------------------------------------------------生物焦质:: markdown()选项(width = 100,max.print = 1000)选项(usefancyquotes = false)knitr ::opts_chunk $ set(eval = as.logical(sys.getenv(sys.getenv(“true”)),cache = as.logical(sys.getenv(“knitr_cache”,“true”)),错误= false)##----------------------------------------------------------------------------------------------------------------------------------------------:10)Rnorm(1:10)摘要(Rnorm(1:10))## -----------------------------------------------------------------------------------------------------------------数据(虹膜)#查找花瓣.Width正好0.2虹膜[虹膜$ petal.width == 0.2,]#查找萼片的那些行.Length小于4.5虹膜[虹膜$ sepal.length <4.5,]#查找属于setosa setosa_iris的所有行=虹膜[虹膜$ speias ==“setosa”,] dim(setosa_iris)## -------------------------------------------------------------------------------------------------------------------------删除包含的列夏洛cters i.e., Species iris <- iris[,!( names(iris) %in% "Species")] dim(iris) # find the mean of the first 4 numerical columns lapply(iris, mean) # simpler: colMeans(iris) # simplify the result sapply(iris, mean) # find the mean for each row. apply(iris, 1 , mean) #simpler : rowMeans(iris) ## ------------------------------------------------------------------------------------------------- # define a vector x <- rnorm(1000) # vectorized calculation y <- x + rnorm(1000, sd=.8) # object construction df <- data.frame(x=x, y=y) # linear model fit <- lm(y ~ x, df) ## ------------------------------------------------------------------------------------------------- par(mfrow=c(1,2)) plot(y ~ x, df, cex.lab=2) abline(fit, col="red", lwd=2) library(ggplot2) ggplot(df, aes(x, y)) + geom_point() + stat_smooth(method="lm") ## ----sessionInfo---------------------------------------------------------------------------------- sessionInfo()