自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(20)
  • 收藏
  • 关注

原创 【w3】split()、interaction()

split()按因子分组> str(split)function (x, f, drop = FALSE, ...X: 向量、列表、dataframef:因子drop:去除 empty factors levelsplit a dataframe> library(datasets)> head(airquality) Ozone Solar.R Wind ...

2020-03-31 10:12:02 97

原创 【w3】tapply

tapply处理分组数据> str(tapply)function (X, INDEX, FUN = NULL, ..., simplify = TRUE)X is a vectorINDEX is a factor or a list of factors (or else they are coerced to factors)> x <- c(rnorm(...

2020-03-30 11:22:07 109

原创 【w3】mapply

mapply( )可以同时对多个list进行运算> str(mapply)function (FUN, ..., MoreArgs = NULL, SIMPLIFY = TRUE, USE.NAMES = TRUE)list(rep(1, 4), rep(2, 3), rep(3, 2), rep(4, 1)) // rep(1,4)-> 将1重复4遍> ma...

2020-03-30 10:46:09 181

原创 【w3】apply

> str(apply)function (X, MARGIN, FUN, ...)MARGIN: 整数向量,指定哪个维度应该被保留> x <- matrix(rnorm(200), 20, 10) // 随机200个数,行20,列10> apply(x, 2, mean) // 保留第二个(也就是列)取平均值,也就是对每列求平均值 [1] 0.04868...

2020-03-30 10:31:43 98

原创 【w3】匿名函数 lapply、sapply

lapply( )对列表X里的每个元素,都函数FUN## function (X, FUN, ...)## {## FUN <- match.fun(FUN)## if (!is.vector(X) || is.object(X))## X <- as.list(X)## .Internal(lapply(X, FUN))## }## <bytecode: 0x...

2020-03-30 10:12:24 303

原创 【w2】Data、Time

类型日期:Data时间:POSIXct、POSIXlt(列表)as.POSIXlt()格式转换as.Date()as.POSIXlt()as.POSIXct()x <- Sys.time()x## [1] "2013-01-24 22:04:14 EST"p <- as.POSIXlt(x) //POSIXlt以列表储存names(unclass(p)) ...

2020-03-27 10:58:57 69

原创 【w2】function、作用域

" …"参数一旦使用“…”,“…”后面的参数必须以指定名称的形式给出,不能隐式给出改造已有函数时用,"…"代表剩下的不变my <- function(x, y, type = "1", ...){ plot(x, y, type = type, ...) // my与plot,除了x、y、type以外其他的参数不变}泛型函数> mean funct...

2020-03-27 10:28:12 60

原创 【w2】repeat、next、return

repeatx0 <- 1tol <- 1e-8repeat { x1 <- computeEstimate() if(abs(x1 - x0) < tol) { break } else { x0 <- x1 }}next/returnfor(i in 1:100) { if(i <= 20) ...

2020-03-26 09:42:30 117

原创 【w2】while 循环

count <- 0while(count < 10) { print(count) count <- count + 1}z <- 5while(z >= 3 && z <= 10) { print(z) coin <- rbinom(1, 1, 0.5) //均匀抛硬币 if(coin == 1) { #...

2020-03-26 09:32:35 172

原创 【w2】for 循环

以下三个for循环有相同结果x <- c("a", "b", "c", "d")for(i in 1:4) { print(x[i])}for(i in seq_along(x)) { print(x[i])}> seq_along(x)[1] 1 2 3 4for(letter in x) { print(letter)}for 语句嵌套x <...

2020-03-26 09:26:39 94

原创 【w2】if 语句

if(x > 3) { y <- 10} else { y <- 0}也可以y <- if(x > 3) { 10} else { 0}else不是必须,如if(<condition1>) {}if(<condition2>) {}

2020-03-26 08:54:05 67

原创 【w1】【swirl】矩阵matrices、 数据框dataframe

矩阵:只能存储一种数据dataframe:可存储多种数据>patients <- c("Bill","Gina","Kelly","Sean") >cbind(patients, my_matrix) //因为矩阵只能存储一种数据,char + int => char patients [1,] "Bill"...

2020-03-25 15:38:55 111

原创 【w1】【swirl】子集

> x [1] -0.2371400 NA 0.5923221 1.9437247 0.3403599 -1.4196407 -1.5748373 NA [9] NA NA 1.3831167 -0.1410241 NA NA -1.7172346 -0.1557368[17] -0...

2020-03-25 14:57:11 85

原创 【w1】【swirl】 NA 、 NAN

NANA: “not available” or “missing”NAN: “not a number” (e.g: 88/0)

2020-03-25 14:30:22 87

原创 【w1】【swirl】向量逻辑判断、paste( )

向量逻辑判断> num_vect <- c(0.5, 55, -10, 6)> tf <- num_vect < 1> tf[1] TRUE FALSE TRUE FALSE字符向量paste(xx, collapse=" " )> my_char <- c("My", "name", "is")> paste(my_ch...

2020-03-25 14:19:53 88

原创 【w1】【swirl】生成序列seq() 复制rep()

seq()生成规律的序列> seq(0,10,by=0.5) [1] 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0[20] 9.5 10.0> my_seq <- seq(5,10,length=30)> seq(a...

2020-03-25 13:59:42 6373

原创 【w1】【swirl】文件路径

设置嵌套文件夹Create a directory in the current working directory called “testdir2” and a subdirectory for it called “testdir3”, all in one command by using dir.create() and file.path()dir.create(file.path...

2020-03-25 13:42:40 134

原创 【w1】向量、矩阵运算

向量> x <- 1:4; y <- 6:9> x + y[1] 7 9 11 13> x > 2[1] FALSE FALSE TRUE TRUE> x >= 2[1] FALSE TRUE TRUE TRUE> y == 8[1] FALSE FALSE TRUE FALSE> x * y[1] 6 14 24 ...

2020-03-24 11:06:13 156

原创 【W1】子集subsetting

基本类型{ : 返回类型与原集合一样,可以提取多个元素[[ : list 或者 Dataframe,只能选提取一个元素$ : 提取list中的一个元素,且该元素必须有name,返回的类型可能和和原来的不同> x <- c("a", "b", "c", "c", "d", "a")> x[1][1] "a"> x[2][1] "b"> x[1:4...

2020-03-24 11:00:13 63

原创 【w1】读取文件

读取文件读取行时读取网页时file:open a connection to a filegzfile: “.gz” 压缩文件bzfile: ".bz"压缩文件url:网页链接con <- file("foo.txt", "r")data <- read.csv(con)close(con)等同于data <- read.csv("foo.txt")因...

2020-03-24 10:01:04 186

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除