Cyber Security Specialist
I want you to act as a cyber security specialist. I will provide some specific information about how data is stored and shared, and it will be your job to come up with strategies for protecting this d...
R 语言常用方法
Sign in to like and favorite skills
I want you to act as a cyber security specialist. I will provide some specific information about how data is stored and shared, and it will be your job to come up with strategies for protecting this d...
I want to act as a Statistician. I will provide you with details related with statistics. You should be knowledge of statistics terminology, statistical distributions, confidence interval, probabillit...
I want you to act as a scientific data visualizer. You will apply your knowledge of data science principles and visualization techniques to create compelling visuals that help convey complex informati...
积累一些在使用 R 语言编程中常用到的一些方法:
$ R CMD BATCH script.R
## 使用 help() 或 ?
help(seq) #或者 ?seq
example(seq)
help.search(ggplot2) #或 ??ggplot2
R CMD BATCH --help R CMD INSTALL --help
可以使用google 的文件类型准测,例如搜索permutations类型的R 语言脚本可以这样搜索
filetype:R permutations -rebol
其中 '-rebol' 是去掉 REBOL 语言中的.R脚本
ifelse(b,u,v)判断b为真返回值为u若为假则返回值为v
> x <- 1:5 > y <- ifelse(x%%2 == 0,'yes','no') > y [1] "no" "yes" "no" "yes" "no"
all()相等即可,而identical()要求完全相等> x <-1:2 > y <- c(1,2) > all(x==y) [1] TRUE > identical(x,y) [1] FALSE > typeof(x) [1] "integer" > typeof(y) [1] "double"
source("script.R")
inc <- function(x) return(x^2)
function(x) return(x^2)
wget "https://download1.rstudio.org/rstudio-xenial-1.0.153-amd64.deb"
sudo dpkg -i rstudio-xenial-1.0.153-amd64.deb
sudo apt-get -f install
ggplot2 画图,可以使用ls() 和 do.call() 方法实现。# test data frame test_data <- data.frame("K"= c('A','B','C'),"V" =c(1,2,3)) # list store 10 data frame ls <- list() id <- 1:10 for (i in id) { ls[[i]] <- test_data } # combine all_data_frame <- do.call("rbind", ls)
使用
ggplot2绘图单次保存PDF没问题,放入循环体中则所有保存的PDF都为空白。是ggplot2的问题,需要加个print()函数解决。
例如:单次保存PDF,没有问题
p <- ggplot(all_data, aes(x = V1, y = V2)) base_dir <- "~/home/test/" pdf(paste0(base_dir,"test.pdf"),height =7.08, width=10.43) p dev.off()
print()函数才能正常保存。for(i in 1:10){ p <- ggplot(all_data, aes(x = V1, y = V2)) base_dir <- "~/home/test/" pdf(paste0(base_dir,i,"test.pdf"),height =7.08, width=10.43) print(p) dev.off() }
theme_set(theme_bw()) 即可library(ggplot2) theme_set(theme_bw())
2021-5-2更新