本教程版权为《糗世界》所有,任何组织或个人不得未经书面许可转载。
在阅读本节前请自测,如果全部都知道正确答案,则可跳过本节。
- 常用函数是否全部掌握(见下表)?
- 请编写一个函数并达到自己的设计要求。
- 为什么R应该尽量避免for循环?
- 什么是引用类(refference class)
常用函数列表
下表是常用函数列表,这里只列出函数名,如果有任何一个函数名称读者感觉陌生的话,请一定使用帮助来查看其内容来填补基础知识的空缺。
# 一切的开始 ?, ??, vignette str # 帮助 help, ? help.search apropos RSiteSearch citation demo example vignette # 环境变量 ls, exists, rm getwd, setwd q source install.packages, biocLite library, require # 文件与目录 dir basename, dirname, tools::file_ext file.path path.expand, normalizePath file.choose file.copy, file.create, file.remove, file.rename, dir.create file.exists, file.info tempdir, tempfile download.file, library(downloader) # 取值与赋值 =, <-, <<- %in%, match $, [, [[, head, tail, subset with, attach, detach assign, get # 逻辑与集合运算 &, |, !, xor &&, || all.equal, identical !=, ==, >, >=, <, <= which is.na, is.finite (is/as).(character/numeric/logical/...) all, any intersect, union, setdiff, setequal sample # 数学 *, +, -, /, ^, %%, %/% abs, sign acos, asin, atan, atan2 sin, cos, tan ceiling, floor, round, trunc, signif exp, log, log10, log2, sqrt max, min, prod, sum cummax, cummin, cumprod, cumsum, diff pmax, pmin range mean, median, cor, sd, var rle # 字符操作 grep, agrep gsub strsplit substr paste chartr nchar tolower, toupper # 条件语句 if for, while next, break switch ifelse # 函数 function missing stop, warning, message match.arg, dotsMethods on.exit return, invisible # Vectors 和 matrix c, matrix # 在类型强制转换时 character > numeric > logical length, dim, ncol, nrow cbind, rbind names, colnames, rownames t diag sweep as.matrix, data.matrix # vector相关 c rep, rep_len seq, seq_len, seq_along rev # Lists & data.frames相关 list, unlist data.frame, as.data.frame split expand.grid # Factors factor, levels, nlevels reorder, relevel cut, findInterval interaction options(stringsAsFactors = FALSE) # Array操作 array dim dimnames # 排序与列表 duplicated, unique merge order, rank, quantile sort table, ftable # 排错 traceback browser recover options(error = ) stop, warning, message tryCatch, try # 输出 print, cat message, warning dput format sink, capture.output # 读写数据 data count.fields read.csv, write.csv read.delim, write.delim read.fwf readLines, writeLines readRDS, saveRDS load, save library(foreign)
表示强烈关注
博主,你好,请问vapply函数中vapply(i39, fivenum, c(Min. = 0, `1st Qu.` = 0, Median = 0, `3rd Qu.` = 0, Max. = 0));最后部分c(Min. = 0, `1st Qu.` = 0, Median = 0, `3rd Qu.` = 0, Max. = 0)为什么这i么写,不是太明白
就是给返回的结果一个模板,在这里,模板是一个vector,所以返回值将会是一个array,array的列名由这个模板的names来决定,列的类型由模板的类型来决定。