# Working With Vectors In R

2018-08-09

Dave Mason continues his quest to learn R, focusing on vectors.  First, he looks at vector-based mathematical operations:

Now we can determine the number of customers gained vs number of customers lost (plus/minus) for each month of the quarter by subtracting one vector from another. Each vector has the same number of elements (three), and the result is also a vector of three elements:

```> net_customer_gain <- new_customers - customers_lost
> net_customer_gain
Jan Feb Mar
-15 30 3 ```

The sum() function can be used to add up all the elements of a vector. Below, we get the total number of new customers and lost customers for the first quarter:

```> sum(new_customers)
[1] 270
> sum(customers_lost)
[1] 252```

To extract multiple elements from a vector, pass in an integer class vector to the square brackets. The values of the integer vector correspond to the elements to be extracted. Here we will extract the first, third, and fourth elements of the jersey_numbers vector:

```> jersey_numbers[c(1,3,4)]
Pierce Rondo Allen 34 9 20 ```

The values of the integer vector can be in any order:

`> jersey_numbers[c(4,1,3)] Allen Pierce Rondo 20 34 9`

Vectors are a critical part of understanding R.

## Dealing With Multicollinearity With R

2018-08-21

Chaitanya Sagar explains the concept of multicollinearity in linear regressions and how we can mitigate this issue in R: Perfect multicollinearity occurs when one independent variable is an exact linear combination of other variables. For example, you already have X and Y as independent variables and you add another variable, Z = a*X + b*Y, […]

## Including R Visuals In Power BI Dashboards

2018-08-21

Parker Stevens shows how to include R visuals in a Power BI dashboard: Let’s finish up this post with a quick example of how to code the elusive line chart with two y-axes. This always seems to be asked in the forums and it’s pretty easy to implement. Follow the same steps as shown above […]

This site uses Akismet to reduce spam. Learn how your comment data is processed.

August 2018
MTWTFSS
« Jul
12345
6789101112
13141516171819
20212223242526
2728293031