Introduction to R and Rstudio

Session - Vectors

Zoë Turner

Vectors

Are a type of data format in R but may be familiar

You can create a vector with function: c() for concatenate/combine. In SQL it would just be () with no c

c(100, 80, 200)

c("beds", "staff", "patients")

# Mixing strings (characters) and numeric values results in all being strings
c("beds", 80, "patients") 

Looking for more than one string

c("Bradford District Care", "Bradford District Care Trust")

# can be made into an object
org_lookup <- c("Bradford District Care", "Bradford District Care Trust")

Using in filter()

Filter by org_name IN the lookup list.

beds_data |> 
  filter(org_name %in% org_lookup) 

Code would look like this in SQL

SELECT *
FROM Table
WHERE Colm IN ('Bradford District Care', 'Bradford District Care Trust')

Negative or NOT IN

Filter by org_name NOT IN the lookup list.

beds_data |> 
  filter(!org_name %in% org_lookup)

In SQL

SELECT *
FROM Table
WHERE Colm NOT IN ('Bradford District Care', 'Bradford District Care Trust')

End session