- 博客(14)
- 收藏
- 关注
原创 tidyverse 包中的功能
https://campus.datacamp.com/courses/introduction-to-the-tidyverse/grouping-and-summarizing?ex=6dplyr%>% 管道函数filter(条件) 筛选casesarrange 根据一个变量正序或倒序排列整个datasetarrange(变量) 正序arrange(desc(变量)) 倒序...
2019-10-10 22:36:50
1249
原创 正则表达式 ex
# Extract the name column from titanicpass_names <- titanic$Name# Create titlestitles <- gsub("^.*, (.*?)\\..*$", "\\1", pass_names)# Call unique() on titlesunique(titles)
2019-10-09 16:33:51
309
原创 查找和替换
查找:grepl 返回逻辑值, TRUE, FALSEgrep 返回 TRUE 的位置emails <- c("john.doe@ivyleague.edu", "education@world.gov", "dalai.lama@peace.org", "invalid.edu", "quant@bigdatacollege.edu", "cookie.mon...
2019-10-09 10:40:19
241
原创 常用函数
常用的函数:abs():round():rev(): reverseseq(): Generate regular sequences.## Default S3 method:seq(from = 1, to = 1, by = ((to - from)/(length.out - 1)), length.out = NULL, along.with = NULL, ...)...
2019-10-08 17:25:00
226
原创 循环
以下内容是我在学习 datacamp上的课程时的笔记。主要记录一些我不太熟悉的要点,以备日后查询使用。课程名称: Intermediate Rlogic operator1. 元素and or not& | !2. 向量> c(TRUE, TRUE, FALSE) & c(TRUE, FALSE, FALSE)[1] TRUE FALSE FALSE&g...
2019-10-08 16:49:29
114
原创 apply 家族函数
lapply提取出列表中的元素方法1:先定义一个函数,然后再 lapply 里面使用它。# Define get_timestamp()get_timestamp <- function(x) { x$timestamp}# Apply get_timestamp() over all elements in logslapply(logs, get_timestamp)...
2019-10-08 16:48:28
259
原创 运算
基本运算R 中 character 是可以比较大小的。R uses the alphabet to sort character strings.首字母在后面的大。大写字母在前, 小写字母在后。> "Hello" > "Good"[1] TRUE> TRUE > FALSE[1] TRUE...
2019-10-08 16:47:31
81
原创 编写函数
Variables that are defined inside a function are not accessible outside that function.函数里面定义的变量在函数外面无法调用。R function cannot change the variable that you input to that function.函数不能改变函数外面已有变量的值。...
2019-10-08 09:42:47
377
原创 基本数据结构
矩阵# 生成矩阵matrix(vector, byrow = TRUE, nrow = 5, dimnames = list(c(), c(), ...)# 矩阵求和rowSums(Amatrix) colSums()# 合并其他的矩阵或向量cbind()rbind()# 矩阵选择元素,要用逗号分开行列,vector就不需要了。...
2019-09-25 10:22:08
201
转载 改变因子水平次序 relevel()函数
问题你想要改变因子水平出现的次序。方案R中有两种不同类型的因子变量:有序和无序。比如{小,中,大}和{钢笔,橡皮擦,铅笔}。对于绝大多数分析而言,一个因子变量是有序还是无序的不重要。如果因子是有序的,那么这个因子水平的特定次序是重要的(小<中<大)。如果因子是无序的,那么因子水平同样会以一定的顺序出现,但这仅仅为了方便而已(钢笔,橡皮擦,铅笔) - 但有时它是重要的,例如它会觉得...
2019-06-28 10:18:03
19775
原创 R tips
library(dplyr)select(xxxs, id, province, score)xxxs: 原始的数据框的名称id ---- score: 想要挑选出来的一组变量名
2019-06-05 10:32:23
234
原创 R 与 SPSS recode variables相同功能的命令
RSPSSrecode variablesx[which(m<2)] <- 0x[which(m>=2)] <- 1
2019-05-28 14:44:39
685
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人