[R] Compute stats on grouped data using dplyr
library(knitr) opts_chunk$set(echo=T, warning=T, fig.width=7, height=7) library(dplyr) dplyr is a great package to process data in a more smooth way: the output of one function can be inject to another function using the operator %>% easily. Today, I would like to share my experience on how to process grouped data and return multiple columns/rows data.
Data We will generate some fake data for this test.
g1<-rep(c("a","b","c"), each=10) g2<-rep(c("A","B"), each=5, length.out=30) x<-rnorm(30,0,10) dat<-data.
[R] What if plots don't show up in blogdown webpage?
Recently I found that the plots generated by R don’t show up in the webpage when I blogdown::serve_site() locally or at netlify.app. A quick google search gave me the following two solutions:
Modify the file config.toml to remove the pattern _files$ from the ignoreFiles list.
Add the option fig.path=some/folder in knitr::opts_chunk$set().
The first one is recommended by Yihui.
For more details, see the following pages:
[R] Create ggplot histograms with y value being fractions
library(knitr) opts_chunk$set(echo=T, warning=F, fig.width=7, fig.height=7, fig.path="static/") library(ggplot2) ## Warning: package 'ggplot2' was built under R version 4.2.3 ggplot2 has been a great tool for making plots. Today, I would like to talk about histogram. It is straight forward to make a histogram with geom_histogram(), but not so when one wants to use fractions instead of counts as values on the y-axis, especially when data are separated into groups. Let’s dive in.
[Jupyter] Connect Jupyter notebook via SSH Tunnel
One can install Jupyter notebook on an AWS EC2 instance via the following command
1 pip install jupyterlab And then start it via the command
1 jupyter-lab --no-browser However, to access it from a client computer may need some tweaking in both AWS EC2 instance and the SSh connection.
AWS EC2 setting Make sure the EC2 instance’s inbound port in security groups include the jupyter server’s port, normally 8888 SSH setting use the following command or alike connect to the EC2 instance
Setup bash in MacOS
I have used Bash in my career for many years and it is so convenient for data analysis.
In MacOS, however, the default shell is zsh. To make use of bash in MacOS, one need the following steps:
Install the latest version of bash One can use brew (the MacOS package manager) to install the latest bash. This will install bash to /usr/local/bin/bash.
1 brew install bash Change the default shell to /usr/local/bin/bash To change the default shell in MacOS, one need run the following command:
Disclaimer
The information provided on fortune9.netlify.app is for general informational purposes only. The website owners and authors do not make any warranties about the completeness, reliability, and accuracy of this information. Any action you take upon the information you find on this website is strictly at your own risk, and the owners and authors will not be liable for any losses and/or damages in connection with the use of our website.
About
This is Zhenguo Zhang’s blog site created using the blogdown package. The theme was forked from @AmazingRise/hugo-theme-diary Thank the authors of these great tools.
About myself Name Zhenguo Zhang
Email zhangz.sci@gmail.com
Interest Statistics Programming Disease diagnosis and treatment Molecular evolution God
[Tips] Adding google calendar using endpoint in Thunderbird
I have used Thunderbird as my daily email and calendar tools for decades for its expandable features via addons. But sometimes, it suffers bugs, just like recently, it stops synchronization with google calender after I updated to version 102.8.0. This bug triggers me to explore potential solutions, and it leads to today’s topic – adding google calendar via endpoint.
Three methods to add google calendar When one wants to add google calendar to Thunderbird, the popup window shows three methods:
[Git] Git hooks - Part 1
Introduction Git hooks allows one to customize git operations automatically, such as checking the code before commit, notify others when committed, or test the code before pushing.
Basically, hooks can be any executable files put under the folder .git/hooks, and named according to the trigger event, such as .git/hooks/pre-commit (triggered when a commit is being generated). The executables can be written in bash, perl, python, R, or anything that can be executed.
[Github] Gist is essentially git repo
Gists are usually single pages, for users to show information such as manual, tutotials, etc.
Actually, they are git repos, too, so one can clone and push to it. To do so, one need to go to a gist page, for example: https://gist.github.com/fortune9/85cb4f128ee5537c4a8cfdf6f2497e84. And then choose “Clone via HTTPS” from the dropdown menu at the top right of the page (as shown in the below figure), and copy the URL after the selection.