HAPPY HOLIDAYS!!!�⛄��� In the spirit of the coming new year and new beginnings, we created a tutorial for getting started or restarted with R. If you are new to R or have dabbled in R but haven’t used it much recently, then this post is for you. We will focus on data classes and types, as well as data wrangling, and we will provide basic statistics and basic plotting examples using real data. Enjoy!
By C.Wright
As with most programming tutorials, let’s start with a good’ol “Hello World�.
1) First Command
1 |
|
1 |
|
2) Install and Load Packages and Data
Now we need some data. Packages are collections of functions and/or data. There are published packages that you can use from the community such as these two packages, or you can make your own package for your own private use.
1 |
|
Now that we have installed the packages, we need to load them.
1 |
|
Each installation of R comes with quite a bit of data! Now we want to load the “quake� data – there are lots of other options.
1 |
|
3) Assigning Objects
Objects can be many different things ranging from a simple number to a giant matrix, but they refer to things that you can manipulate in R.
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
4) Assigning Objects with Multiple Elements
Now lets assign a more complex object
1 |
|
5) Classes
There are a variety of different object classes. We can use the function class() to tell us what class an object belongs to.
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
6) Subsetting Data
Now that we can assign or instantiate objects, let’s try to look at or manipulate specific parts of more complex objects.
Lets create an object of male heights by grabbing rows from heightdf.
1 |
|
1 |
|
1 |
|
1 |
|
Here is another way using a package called dpylr:
1 |
|
Here we are creating an object of height data for males over 6 feet.
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
Now let’s create an object by grabbing part of an object based on its columns.
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
Now let’s try to look at/grab specific values.
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
This allows you to grab random data points.
1 |
|
1 |
|
1 |
|
1 |
|
8) More Statistical Tests
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
Let’s do a more classic anova – using a categorical variable with more than two categories.
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
For additional help take a look at these links:
Free courses and tutorials
Also follow our blog for more helpful posts.
This image came from: https://www.pinterest.com/pin/89790586304535333/
Acknowledgements
This blog post was made possible thanks to:
Reproducibility
1 |
|
Related