{"id":23061827,"url":"https://github.com/rrwen/r-reference","last_synced_at":"2025-07-02T17:32:45.548Z","repository":{"id":91307965,"uuid":"65477879","full_name":"rrwen/r-reference","owner":"rrwen","description":"Quick reference to learning R","archived":false,"fork":false,"pushed_at":"2017-08-08T17:50:49.000Z","size":371,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"intro","last_synced_at":"2025-04-03T07:19:57.996Z","etag":null,"topics":["analysis","beginner","data","guide","introduction","learn","r","reference","statistics","stats","syntax"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rrwen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-11T14:54:24.000Z","updated_at":"2017-08-08T17:54:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"1cc0e4b3-c612-448b-9ed7-fb1b41941248","html_url":"https://github.com/rrwen/r-reference","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rrwen/r-reference","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrwen%2Fr-reference","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrwen%2Fr-reference/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrwen%2Fr-reference/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrwen%2Fr-reference/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rrwen","download_url":"https://codeload.github.com/rrwen/r-reference/tar.gz/refs/heads/intro","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrwen%2Fr-reference/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263184675,"owners_count":23427067,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analysis","beginner","data","guide","introduction","learn","r","reference","statistics","stats","syntax"],"created_at":"2024-12-16T03:18:35.462Z","updated_at":"2025-07-02T17:32:45.520Z","avatar_url":"https://github.com/rrwen.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# R Reference\n  \n  \nRichard Wen (rrwen.dev@gmail.com)  \n  \nA quick introduction to R, which includes installation, basic examples, and references to learning resources.  \n\n**Requirements**\n* [R](https://www.r-project.org/) [[Download](http://cran.r-project.org/mirrors.html)]: a free programming language that is widely used for statistics and data analysis\n* [RStudio](https://www.rstudio.com/products/rstudio/) [[Download](https://www.rstudio.com/products/rstudio/download2/#download)]: a graphical interface and various tools to make writing R code easier\n\n## Contents\n**[1.0 Quick Start](https://github.com/rrwen/r-reference#10-quick-start)**  \n**[2.0 Basic Examples](https://github.com/rrwen/r-reference#20-basic-examples)**  \n* [Help](https://github.com/rrwen/r-reference#help)  \n* [Comments and Output](https://github.com/rrwen/r-reference#comments-and-output)  \n* [Math](https://github.com/rrwen/r-reference#math)  \n* [Variables](https://github.com/rrwen/r-reference#variables)  \n* [Loops](https://github.com/rrwen/r-reference#loops)  \n* [Vectors](https://github.com/rrwen/r-reference#vectors)  \n* [Dataframes](https://github.com/rrwen/r-reference#dataframes)  \n* [Summaries and Plots](https://github.com/rrwen/r-reference#summaries-and-plots)  \n* [Read and Write](https://github.com/rrwen/r-reference#read-and-write)  \n* [Packages and Libraries](https://github.com/rrwen/r-reference#packages-and-libraries)  \n  \n**[3.0 References](https://github.com/rrwen/r-reference#30-references)**  \n  \n## 1.0 Quick Start\n1. Install [R](http://cran.r-project.org/mirrors.html) and [RStudio](https://www.rstudio.com/products/rstudio/download2/#download)\n2. Open RStudio and begin coding in R:  \n  * **Script Editor**: Run, edit, and save R code using script files (.R)  \n  * **Console**: Execute and output code  \n  * **Variables/Objects**: Inspect variables and objects in the global environment  \n  * **Help/Plots/Misc**: Visualization, help documentation, package, and file interfaces \n  \n\u003cimg src=\"https://github.com/rrwen/r-reference/blob/intro/ui.PNG\"  width=\"800;\"/\u003e\n\n## 2.0 Basic Examples\nThe following can be run in either the console or the script editor.\n\n### Help\nGet help documentation using `?`\n```r\n?read.table\n?write.table\n?vector\n?data.frame\n?summary\n?plot\n?lm\n```\n\n### Comments and Output\nCommenting using `#` and console output using `print()`\n```r\n# This is a comment, it does not get executed\nprint(\"Some text\") # It can be used on the same line as the actual code\n```\n\n### Math\nSimple arithmetic operations:\n* addition `+`\n* subtraction `-`\n* multiplication `*`\n* division `/`\n* exponent `^`\n```r\n1 + 1  # add\n2 - 1  # sub\n2 * 2  # multiply\n10 / 2  # div\n4^2  # exp\n```\n\n### Variables\nVariable assignment using `\u003c-`\n```r\nx \u003c- 1\ny \u003c- x + 1  # y == 2\n```\n\n### Loops\nBasic `for` loop\n```r\nx \u003c- 0\nfor (i in 1:5) {  # Add 1 to x, 5 times\n  x \u003c- x + 1\n}\n```\n\n### Vectors\nCreate a vector using `c()`\n```r\nheight \u003c- c(4.8, 4.5, 5.75)\neyeColor \u003c- c(\"blue\", \"brown\", \"green\")\neyeColor[1]  # select the 1st eyeColor\nheight[c(1,3)]  # select 1st and 3rd height\nheight + 0.1  # add 0.1 to all heights\n```\n\n### Dataframes\nCreate a dataframe (table-like structure) using `data.frame()`\n```r\ndataset \u003c- data.frame(height=c(4.8, 4.5, 5.75),\n                      eyeColor=c(\"blue\", \"brown\", \"green\"))\ndataset[1, ]  # select 1st row\ndataset[, 2]  # select 2nd column\ndataset$eyeColor  # select 2nd column by name\n```\n\n### Summaries and Plots\nObtain a summary or plot using `summary()` or `plot()`\n```r\nsummary(dataset)  # mean, median, mode, stdev, etc\nplot(dataset)  # height vs eyeColor\n```\n\n### Read and Write\nRead/write table-formatted data using `read.table`\n```r\ndataset \u003c- read.table(\"file.txt\")\nwrite.table(dataset, \"new_file.txt\")\n```\n\n### Packages and Libraries\nPackage management using `install.packages()` and `remove.packages()`  \nLoad package libraries using `library()`\n```r\ninstall.packages(\"ggplot2\")\nremove.packages(\"ggplot2\")\nlibrary(utils)\n```\n\n## 3.0 References\n* [Base R Cheatsheet](https://www.rstudio.com/wp-content/uploads/2016/06/r-cheat-sheet.pdf) by Mhairi McNeill for more basic R code\n* [RStudio cheatsheets](https://www.rstudio.com/resources/cheatsheets/) for quick R code references\n* [Online learning resources](https://www.rstudio.com/online-learning/#R) suggested by RStudio\n* A short [12 page introduction to R](https://www.rstudio.com/resources/cheatsheets/) by Paul Torfs and Claudia Brauer\n* Google's [R Style Guide](https://google.github.io/styleguide/Rguide.xml) for R coding practices\n* [Advanced R](http://adv-r.had.co.nz/) by Hadley Wickham\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frrwen%2Fr-reference","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frrwen%2Fr-reference","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frrwen%2Fr-reference/lists"}