R IN WINDOWS # Download here and install.
R IN UBUNTU 18.04 # sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 && \ sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran40/' && \ sudo apt update && \ sudo apt install -y r-base r-base-dev libcurl4-openssl-dev libssl-dev build-essential && \ sudo -i R # install packages as root, so all users can use. Commonly used packages:
install.packages(c('devtools', 'digest', 'repr', 'IRdisplay', 'crayon', 'pbdZMQ', 'ggplot2', 'IRkernel', 'ggpubr')) DigitalOcean
...
Three methods.
//TODO: summary of: paper3 gpu 430.R
This is part of PML notes. HDD: r_data_table_start
Prepare Data # library(dplyr) library(readr) library(data.table) hero = " name, alignment, gender, publisher Magneto, bad, male, MarvelDuplicate Storm, good, female, MarvelDuplicate Batman, good, male, DC Joker, bad, male, DC Catwoman, bad, female, DC Hellboy, good, male, Dark Horse Comics " hero = read_csv(hero, trim_ws = TRUE, skip = 1) hero = data.table(hero) publisher = " publisher, yr_founded DC, 1934 MarvelDuplicate, 1939 MarvelDuplicate, 8888 Image, 1992 " publisher = read_csv(publisher, trim_ws = TRUE, skip = 1) publisher = data.
...
Python alternatives to ggplot2: pygg (NOT working), ggpy (ggplot in py) from yhat (NOT working and not in maintance). Please use rpy2 to “source()” R files.
Note: this blog is mainly used to prepare data, for plotting code, see:
O’Reilly 2013 - R Graphics Cookbook ggplot2 cheatsheet Be Awesome in ggplot2: A Practical Guide, (bak) 3D PLOT # scatter # OBS: order of using commands.
surface # OBS: order of using commands.
...
It has been a long time since I started using R. Recently, I found some old notes, and I prefer to put it in digital archive, this blog post is to achieve the purpose.
DT (data.table) # data.table cheat sheet
This data.table (DT) instruction is also available on my github, ispiared by
this ref
//TODO # //TODO: summarize Solve common R problems efficiently with data.table which is must-read. backup
//TODO: summarize High-performance Solution in R
...
Note: feather-format is desigend to transfer data between Py & R [stackoverflow, feather-doc].
.FE # OBS: only for data.frame type, not even arrays.
py (feather-format) # Requires: pip install feather-format. (OBS: feather-format NOT feather.)
write:
import numpy as np import pandas as pd df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C':[7,8,9]}, index=['one', 'two', 'three']) import feather feather.write_dataframe(df.reset_index(drop=True), 'df.fe') (though the df is created by pandas)
read:
import feather df = feather.
...