随笔分类 - R语言
摘要:seq(as.Date("2020-02-01"), length=12, by="1 month") - 1 [1] "2020-01-31" "2020-02-29" "2020-03-31" "2020-04-30" "2020-05-31" "2020-06-30" "2020-07-31"
阅读全文
摘要:R for循环示例 for(i in 1:10){ print(i) } for(i in seq(10)){ print(i) } a <- list(1,2,4) for(i in a){ print(i) } for (year in c(2010,2011)){ print(paste("T
阅读全文
摘要:diamonds 是内置数据集library(ggplot2) ggplot(diamonds, aes(carat)) + geom_density() ggplot(diamonds, aes(depth, colour = cut)) + geom_density() + xlim(55, 7
阅读全文
摘要:RData文件存储的是对象,比如a=5 > num <- seq(0, 5, length.out=10) #创建对象num > num [1] 0.0000000 0.5555556 1.1111111 1.6666667 2.2222222 2.7777778 3.3333333 3.88888
阅读全文
摘要:group_by(id) %>% arrange(desc(date)) %>% #按日期降序 filter(row_number()==1) %>% ungroup 参考:https://stackoverflow.com/questions/13279582/select-the-first-r
阅读全文
摘要:> a = system("ls aaaaa;echo $?", intern = TRUE)ls: 无法访问aaaaa: 没有那个文件或目录> a[1] "2" 更多:https://stat.ethz.ch/R-manual/R-devel/library/base/html/system.ht
阅读全文
摘要:i <- 3 assign(paste0('myVar', i), 1:5) myVar3 ## [1] 1 2 3 4 5 更多:https://bbs.pinggu.org/thread-6853714-1-1.html
阅读全文
摘要:typeof()返回值: integer、double、single、float class(): 查看变量类型,vector、data.frame、matrix、factor、list
阅读全文
摘要:https://rstudio.github.io/DT/009-searchable.html library(DT) iris2 = iris[46:55, ] datatable( iris2, filter = 'top', options = list( # columnDefs = li
阅读全文
摘要:id = c(1,2,1,4,2) year = c(1980, 1990, 2000, 2010, 2020) salary = c(2000, 3000, 4000, 5000, 6000) df = data.frame(id, year, salary); df # id year sala
阅读全文
摘要:id = c(1,2,1,4,2) year = c(1980, 1990, 2000, 2010, 2020) salary = c(2000, 3000, 4000, 5000, 6000) df = data.frame(id, year, salary); df # id year sala
阅读全文
摘要:mtcars是R Studio自带的数据集datasets里包含的,可以直接使用或datasets::iris这样引用.library(help = "datasets")可以看到详细的数据集列表. > mtcars %>% head() mpg cyl disp hp drat wt qsec v
阅读全文
摘要:iris是R Studio自带的数据集datasets里包含的,可以直接使用或datasets::iris这样引用.library(help = "datasets")可以看到详细的数据集列表. > # 默认升序 > iris %>% arrange(Sepal.Length) %>% head()
阅读全文
摘要:library(dplyr) df <- tibble::tibble( x = sample(10, 100, rep = TRUE), y = sample(10, 100, rep = TRUE) ) df # 以全部列去重 distinct(df) # 以列x去重,仅返回去重后的x列 dis
阅读全文
摘要:推荐数据集: 1.csv直接下载,有文档介绍及R代码示例 https://vincentarelbundock.github.io/Rdatasets/datasets.html 2.csv直接下载,有文档介绍及R代码示例 http://www-eio.upc.edu/~pau/cms/rdata/
阅读全文
摘要:Linux:相对路径,存放到了和代码相同目录 write.table(x, "./abc.txt") Windows:绝对路径 write.table(x, "D:/codes/abc.txt")
阅读全文