Skip to content

Commit

Permalink
Introduction update
Browse files Browse the repository at this point in the history
  • Loading branch information
vzrg-tamu committed Jan 16, 2024
1 parent 3d5a9b6 commit 9ee99de
Show file tree
Hide file tree
Showing 44 changed files with 1,206 additions and 124 deletions.
1 change: 1 addition & 0 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ book:
- ch1.qmd
- ch2.qmd
- ch3.qmd
- ch4.qmd

format:
html:
Expand Down
Binary file modified awesome_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 19 additions & 9 deletions ch1.qmd
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
---
title-block-banner: true
---

# Operators and data types

## Basic operators

In this section, we will learn about some basic R operators that are used to perform operations on values and variables. Some most commonly used operators are shown in the table below.
In this section, we will learn about some basic R operators that are used to perform operations on variables. Some most commonly used operators are shown in the table below.

<center>![](images/Basic_operators.png){width="70%"}</center>

> R follows the conventional order (sequence) to solve mathematical operations, abbreviated as BODMAS: Brackets, Orders (exponents), Division, Multiplication, Addition, and Subtraction
```{r Chapter 1, message = FALSE, warning = FALSE}
2+4+7 # Sum
2+4+7 # Sum
4-5 # Subtraction
2*3 # Multiplication
1/2 # Division
# Order of operation
1/2*3+4-5
1/2*(3+4-5)
1/(2*(3+4-5))
1/(2*3+4-5)
## Notice how output changes with the placement of operators
# Notice how output changes with the placement of operators
# Other operators:
2^3
Expand All @@ -26,7 +32,7 @@ sqrt(4)
pi
# Clear the Environment
rm(list=ls())
rm(list=ls()) # rm is for remove,ls is short for list. The empty parenthesis i.e. () signifies all content.
```

## Basic data operations
Expand All @@ -36,8 +42,8 @@ In this section, we will create some vector data and apply built-in operations t
```{r Basic data operation, message = FALSE, warning = FALSE}
# The "is equal to" or "assignment operator in R is "<-" or "="
# Generate sample data
data<-c(1,4,2,3,9)
# Generate sample data. Remember "c" comes from for "concatenate".
data<-c(1,4,2,3,9) # Try data = c(1,4,2,3,9). Is there any difference in data in both cases?
# rbind combines data by rows, and hence "r"bind
# cbind combines data by columns, and hence "c"bind
Expand Down Expand Up @@ -74,16 +80,20 @@ sd(data) # Standard deviation
var(data) # Variance
# Text data
data=c("TAMU","GEOS","BAEN","WMHS")
data=c("LSU","SPESS","AgCenter","Tigers")
data # View
data[1]
# Mixed data
data=c(1,"GEOS",10,"WMHS") # All data is treated as text if one value is text
data[3] # Note how output is in quotes i.e. "10"
data=c(1,"LSU",10,"AgCenter") # All data is treated as text if one value is text
data[3] # Note how output is in quotes i.e. "10"
```


> *For help with a function in R, just type ? followed by the function to display information in the help menu. Try pasting `?sd` in the console.*

## Data types

In R, data is stored as an "array", which can be 1-dimensional or 2-dimensional. A 1-D array is called a "vector" and a 2-D array is a "matrix". A table in R is called a "data frame" and a "list" is a container to hold a variety of data types. In this section, we will learn how to create matrices, lists and data frames in R.
Expand Down
1 change: 1 addition & 0 deletions ch3.qmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title-block-banner: true
---

# Plotting with ggplot2

## Import libraries and create sample dataset
Expand Down
49 changes: 49 additions & 0 deletions ch4.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
title-block-banner: true
---
## EXCERCISE 1
Retrieving data from USCRN: Extract sample data from a climate reference site in Lafayette, LA, USA for 2021.

```{r}
#| label: import data
#| warning: false
# Yearly data from the sample station
CRNdat = read.csv(url("https://www.ncei.noaa.gov/pub/data/uscrn/products/daily01/2021/CRND0103-2021-LA_Lafayette_13_SE.txt"), header=FALSE,sep="")
# Data headers
headers=read.csv(url("https://www.ncei.noaa.gov/pub/data/uscrn/products/daily01/headers.txt"), header=FALSE,sep="")
# Column names as headers from the text file
colnames(CRNdat)=headers[2,1:ncol(CRNdat)]
# Replace fill values with NA
CRNdat[CRNdat == -9999]=NA
CRNdat[CRNdat == -99]=NA
CRNdat[CRNdat == 999]=NA
# View data sample
library(kableExtra)
dataTable = kbl(head(CRNdat,3),full_width = F)
kable_styling(dataTable,bootstrap_options = c("striped", "hover", "condensed", "responsive"))
```

```{r}
#| label: fig-density
#| fig-cap: "Soil moisture values at USCRN station in Texas"
#| fig-subcap:
#| - "Time series of SM"
#| - "SM kernel density"
#| layout-ncol: 2
# Sample plot for soil moisture
x=CRNdat$SOIL_MOISTURE_20_DAILY
# Plot time series and density distribution
plot(x, type="l", ylab="Soil moisture (v/v)",
col="cyan4", lwd=3)
plot(density(na.omit(x)), main=" ", xlab="",
col="cyan4", lwd=3)
```
224 changes: 124 additions & 100 deletions docs/ch1.html

Large diffs are not rendered by default.

Binary file modified docs/ch1_files/figure-html/Data types-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ch1_files/figure-html/Data types-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions docs/ch2.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ <h1 class="title"><span class="chapter-number">3</span>&nbsp; <span class="chapt
<a href="./ch3.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Plotting with ggplot2</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./ch4.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">EXCERCISE 1</span></span></a>
</div>
</li>
</ul>
</div>
Expand Down
Binary file modified docs/ch2_files/figure-html/Multivariate data frame-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ch2_files/figure-html/Multivariate data frame-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ch2_files/figure-html/Multivariate data frame-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ch2_files/figure-html/Multivariate data frame-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ch2_files/figure-html/Univariate data-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ch2_files/figure-html/Univariate data-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ch2_files/figure-html/data frame and list-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ch2_files/figure-html/data frame and list-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ch2_files/figure-html/data frame and list-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ch2_files/figure-html/data frame and list-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ch2_files/figure-html/data frame and list-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ch2_files/figure-html/data frame and list-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ch2_files/figure-html/time series-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ch2_files/figure-html/using layout-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ch2_files/figure-html/using layout-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 16 additions & 6 deletions docs/ch3.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<script src="site_libs/quarto-search/fuse.min.js"></script>
<script src="site_libs/quarto-search/quarto-search.js"></script>
<meta name="quarto:offset" content="./">
<link href="./ch4.html" rel="next">
<link href="./ch2.html" rel="prev">
<script src="site_libs/quarto-html/quarto.js"></script>
<script src="site_libs/quarto-html/popper.min.js"></script>
Expand Down Expand Up @@ -174,6 +175,12 @@ <h1 class="title"><span class="chapter-number">4</span>&nbsp; <span class="chapt
<a href="./ch3.html" class="sidebar-item-text sidebar-link active">
<span class="menu-text"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Plotting with ggplot2</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./ch4.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">EXCERCISE 1</span></span></a>
</div>
</li>
</ul>
</div>
Expand Down Expand Up @@ -291,12 +298,12 @@ <h2 data-number="4.3" class="anchored" data-anchor-id="multivariate-plots"><span
<pre><code># A tibble: 6 × 4
Year January Month Value
&lt;dbl&gt; &lt;dbl&gt; &lt;chr&gt; &lt;dbl&gt;
1 1913 79.4 Jan -8.59
2 1913 79.4 Feb -7.94
3 1913 79.4 Mar -7.35
4 1914 62.0 Jan -4.93
5 1914 62.0 Feb -7.10
6 1914 62.0 Mar -13.1 </code></pre>
1 1913 19.5 Jan -11.0
2 1913 19.5 Feb -8.82
3 1913 19.5 Mar -2.55
4 1914 6.44 Jan -6.10
5 1914 6.44 Feb -6.49
6 1914 6.44 Mar -5.51</code></pre>
</div>
</div>
<p><strong>Line plot</strong></p>
Expand Down Expand Up @@ -615,6 +622,9 @@ <h2 data-number="4.3" class="anchored" data-anchor-id="multivariate-plots"><span
</a>
</div>
<div class="nav-page nav-page-next">
<a href="./ch4.html" class="pagination-link">
<span class="nav-page-text"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">EXCERCISE 1</span></span> <i class="bi bi-arrow-right-short"></i>
</a>
</div>
</nav>
</div> <!-- /content -->
Expand Down
Binary file modified docs/ch3_files/figure-html/density plot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ch3_files/figure-html/grid plotting and saving 1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ch3_files/figure-html/histogram-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ch3_files/figure-html/line plot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ch3_files/figure-html/load packages and data for plots-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ch3_files/figure-html/load packages and data for plots-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9ee99de

Please sign in to comment.