Yearly Archives: 2018

Home/2018

Note for R Parallel Computing

By |2018-08-31T12:58:39-04:00August 31st, 2018|Categories: Note笔记|Tags: , , , |

#并行计算-parallel包 #parallel包的思路和lapply函数很相似,都是将输入数据分割、计算、整合结果。只不过并行计算是用到了不同的cpu来运算。下面的例子是解决欧拉问题的第14个问题。 # 并行计算euler14问题 # 自定义函数以返回原始数值和步数 library(parallel) func <- function(x) { n = 1 raw <- x while (x > 1) { x <- ifelse(x%%2==0,x/2,3*x+1) n = n + 1 } return(c(raw,n)) } library(parallel) # 用system.time来返回计算所需时间 system.time({ x <- 1:1e6 cl <- makeCluster(4) # 初始化四核心集群 results <- parLapply(cl,x,func) # lapply的并行版本 res.df <- do.call('rbind',results) # 整合结果 stopCluster(cl) [...]

R Multiplots in ggplot2

By |2018-08-31T12:55:49-04:00August 31st, 2018|Categories: Note笔记, Technique技术|Tags: , , , |

#Multiplot in ggplot2 install.packages("gridExtra") library("gridExtra") install.packages("cowplot") library("cowplot") df <- ToothGrowth # Convert the variable dose from a numeric to a factor variable df$dose <- as.factor(df$dose) head(df) #----Cowplot---- # The cowplot package is an extension to ggplot2 #and it can be used to provide a publication-ready plots. library(cowplot) # Default plot bp <- ggplot(df, aes(x=dose, y=len, color=dose)) [...]

R Use profvis Package for Better System Monitoring

By |2018-08-31T12:33:03-04:00August 31st, 2018|Categories: Note笔记|Tags: , , , |

Here is an interesting package called 'profvis' that I recently get to know about. It is quite useful when you are trying to locate the place where takes the longest time when running the code. Below is an official example. #R system monitoring install.packages('profvis') library(profvis) # To run code with profiling, wrap the expression in profvis(). [...]

Notes on Creating Beautiful Heatmaps in R

By |2018-08-31T12:20:23-04:00August 31st, 2018|Categories: Note笔记|Tags: , , |

Date: 2017/04/16 source: http://math.usu.edu/jrstevens/stat5570/2.3.Clustering.pdf # Heatmap Trial library(cluster) library(RColorBrewer) set.seed(123) x1 <- c(rnorm(20,sd=.05), rnorm(20,mean=1,sd=.05), rnorm(20,mean=1.5,sd=.05)) x2 <- 4+c(rnorm(20,sd=2), rnorm(20,mean=8,sd=1.5), rnorm(20,mean=8,sd=1)) x1.sc <- x1/sd(x1) x2.sc <- x2/sd(x2) hmcol <- colorRampPalette(brewer.pal(10,"RdBu"))(256) csc <- c(hmcol[50],hmcol[200]) # define side colors heatmap(cbind(x1.sc,x2.sc),scale="column",col=hmcol, ColSideColors=csc,cexCol=1.5,cexRow=.5) # ---- try with ALL datasets source("http://bioconductor.org/biocLite.R") biocLite(c('affy', 'ALL')) # download packages library(affy); library(ALL); data(ALL) gn <- featureNames(ALL) [...]

R for Data Science Study Notes

By |2018-08-10T02:09:56-04:00August 10th, 2018|Categories: Note笔记|Tags: , , , |

Just finished an amazing tutorial textbook in 3 consecutive days. is such a fantastic book for both beginners and mid-level learners like me to review all the aspects of Data Science using R systematically and grab a more thorough understanding of data tidying methods, how to treat different data format effectively and utilize dplyr, lubridate and [...]

This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.

This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.
Go to Top