# R quick start guide

This article introduces some basic R concepts that may help when using the UKFE package as well as links to other R resources.

# R basics

## Numerical operations

In R, we can perform arithmetic operations, for example, try typing the following in the console:

    1 + 2
    #> [1] 3
    3 - 5
    #> [1] -2
    4 * 2
    #> [1] 8
    6 / 3
    #> [1] 2

## Objects

An object acts as a container for storing data. For example, you can assign some text (called a string) to the object called `greeting`:

    greeting <- "Hello!"

You can then use this variable later:

    greeting
    #> [1] "Hello!"

Numbers can be stored in numeric variables:

    number <- 1

These can then be used in arithmetic operations:

    number + 10
    #> [1] 11

## Vectors

Vectors are one-dimensional arrays that store data. Each element has the same data type. To create one, you can use the `c` function, which stands for `combine` or `concatenate`. UKFE uses lots of numeric vectors.

    vec <- c(1, 2, 3, 4)

You can perform calculations with vectors:

    a <- c(1, 2, 3)
    b <- c(4, 5, 6)
    a + b
    #> [1] 5 7 9

    a <- c(1, 2, 3)
    a * 2
    #> [1] 2 4 6

## Data frames

Data frames are structures made up of rows and columns, similar to the structure of a csv file. Each column in a data frame is a vector.

    column_1 <- c(1, 2, 3, 4)
    column_2 <- c(4, 3, 2, 1)

    df <- data.frame(column_1, column_2)
    head(df)
    #>   column_1 column_2
    #> 1        1        4
    #> 2        2        3
    #> 3        3        2
    #> 4        4        1

## Functions

R contains some built-in functions. For example, we can use the `mean()` function to find the mean of a vector:

    mean(c(1, 2, 3))
    #> [1] 2

We can also use a variable inside a function:

    vector_of_numbers <- c(2, 4, 6)
    mean(vector_of_numbers)
    #> [1] 4

You can learn about the functions in the UKFE package using this documentation and the functions’ help files.

# Learning resources for R

If you are finding the UKFE documentation difficult to follow, or if you would like to further develop your knowledge of R, there are many resources available to help. The following suggestions are particularly useful for those who are new to R or programming in general.

## Online books

- R for Data Science and R Programming for Data Science are introductory texts, freely available online. They cover the essentials of working with R, including practical examples and exercises.
- Both books include lists of additional resources in their ‘R Resources’ sections.

## Interactive courses

- DataCamp offers interactive, browser-based courses in R. Some introductory content is available for free.

## Webinars and video tutorials

- Posit Webinars feature recorded sessions on a wide range of topics, from beginner to advanced level.
- YouTube also hosts many high-quality R tutorials and lecture series. Searching for “R programming for beginners” will return playlists of relevant material.
- Coursera offers structured R courses from universities such as Johns Hopkins and the University of Washington. These courses are suitable for beginners and are sometimes available for free or with financial aid.

## Blogs and tutorials

- R-bloggers contains tutorials and articles from across the R community. Posts range from beginner-friendly guides to advanced techniques, and often include worked examples and practical applications.

## Support and questions

- If you have questions specifically about this package, you may find it helpful to visit the GitHub Discussions forum associated with the repository. This is a good place to ask questions, report issues, or see if others have encountered similar problems.