From the course: R for Data Science: Lunch Break Lessons
exists
From the course: R for Data Science: Lunch Break Lessons
exists
- [Instructor] Don't reinvent the wheel. When you're running R, you shouldn't redefine something that's already existing. And a way to determine if something is already existing is to use the R command exists. So let's take a look at how to use exists to save your code some time and effort. In the code window on line two, I've created an if else statement. And the first thing that it says is if exists DefinedVector, then line three is a comment that says avoid repeating long and expensive routine. If DefinedVector already exists, you shouldn't redefine vector. Now, if DefinedVector doesn't exist, we'll drop down to line five and print it's NOT defined. So let's go ahead and run that and just see what happens if DefinedVector is not defined. No surprise, our command comes back and says it's not defined and if you look over in the global environment in the right-hand side, you'll see that the environment is empty. DefinedVector is not defined. So let's fix that. Let's DefinedVector. And we'll put something into it, anything. And now you can see that DefinedVector shows up in the global environment to the right-hand side. Now when we run our command, starting at line two, we get back the message it's already defined. So exists looks in the current environment to see if an object is already existing. Now, an object could be a vector or it could be a function or a matrix or a DataFrame or any R object that you can create. Use exists to save yourself time and to improve the execution speed of your R functions.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
-
Exercise File: Subscribe to access.
Ex_Files_R_Data_Lunch_Break.zip -
Exercise File: Subscribe to access.
Ex_Files_R_for_Data_Sci_2021_Q3.zip -
Exercise File: Subscribe to access.
Ex_Files_R_for_Data_Sci_2021_Q4.zip -
Exercise File: Subscribe to access.
Ex_Files_R_for_Data_Sci_2022_Q1.zip -
Exercise File: Subscribe to access.
Ex_Files_R_for_Data_Sci_2022_Q2.zip -
Exercise File: Subscribe to access.
Ex_Files_R_for_Data_Sci_2022_Q3.zip -
Exercise File: Subscribe to access.
Ex_Files_R_for_Data_Sci_2022_Q4.zip -
Exercise File: Subscribe to access.
Ex_Files_R_for_Data_Sci_2023_Q1.zip -
Exercise File: Subscribe to access.
Ex_Files_R_for_Data_Sci_2023_Q2.zip
Download courses and learn on the go
Watch courses on your mobile device without an internet connection. Download courses using your iOS or Android LinkedIn Learning app.
Contents
-
-
R built-in data sets5m 21s
-
Vector math5m 57s
-
Subsetting7m 17s
-
R data types: Basic types7m 34s
-
R data types: Vector5m 16s
-
R data types: List5m 27s
-
R data types: Factor5m 15s
-
R data types: Matrix8m 48s
-
R data types: Array3m 50s
-
R data types: Data frame6m 44s
-
Data frames: Order and merge8m 10s
-
Data frames: Read and update4m 44s
-
-
-
Switch on factors2m 18s
-
Any/all4m 13s
-
sub, gsub, regex, and backreferences4m 52s
-
agrep and fuzzy matching4m 44s
-
combn finds combinations2m 33s
-
edit, fix, and dataentry4m 57s
-
zeallot5m 30s
-
menu2m 58s
-
person3m 16s
-
txtProgressBar3m 13s
-
zip and tar3m 50s
-
bitwise4m 11s
-
by is like tapply4m 15s
-
Update your R4m 1s
-
-
-
matrix, row, and column4m 41s
-
cumsum, cumprod, cummax, an dcummin4m 11s
-
issymetric3m 14s
-
file.access4m
-
file.info4m 1s
-
dput and dget4m 35s
-
Sort a data frame by multiple columns4m 12s
-
diag2m 52s
-
crossprod3m 13s
-
upper.tri and lower.tri3m 7s
-
strsplit() splits strings at matched characters2m 37s
-
Use setnames() to change the name of an object5m 3s
-
Change the structure of a vector with stack()4m 44s
-
-
-
Use droplevels() to simplify factors3m 26s
-
Use .Rmd for documentation7m 2s
-
Use rep() to create long repetitive vectors4m 58s
-
Use format() to improve readability4m 53s
-
Use pmax() and pmin() to discover the scope of paired vectors5m 18s
-
Use print() for more than you do now4m 55s
-
Use range() and extendrange() to analyze and manipulate groups of numbers3m 42s
-
Evaluate the importance of a number with rank()4m 51s
-
Use saveRDS() and readRDS() to serialize objects3m 26s
-
Use regular expressions with regexpr() and gregexpr()4m 22s
-
message5m 21s
-
regexpr5m 45s
-
diff4m 50s
-
-
-
exists1m 57s
-
formulas4m 42s
-
RPres5m 26s
-
lattice: Introduction5m 8s
-
lattice: xyplot5m 37s
-
lattice: cloud and wireframe4m 31s
-
lattice: contourplot4m 8s
-
lattice: barchart4m 57s
-
lattice: splom charts6m 14s
-
lattice: panels4m 50s
-
lattice: stripplot3m 18s
-
whichmin and whichmax2m 52s
-
par: font, size, color5m 10s
-
-
-
par: margins6m 21s
-
par: pch and points3m 17s
-
legend5m 26s
-
identical3m 28s
-
Matrix math: Overview of functions1m 38s
-
Matrix math review4m 50s
-
matrix: solve systems4m 11s
-
matrix: solve inverse3m 32s
-
matrix: backsolve and forwardsolve5m 24s
-
Matrix: Determinant3m
-
Arrays and outer2m 49s
-
Matrix: Crossproduct2m 7s
-
Matrix SVD and QR decomposition3m 39s
-
-
-
Analyze term-document matrix5m 38s
-
NLP packages: Tidytext5m 7s
-
NLP packages: Quanteda7m 40s
-
NLP packages: Sentiment analysis8m 28s
-
Word clouds3m 10s
-
Hidden features of installr4m 1s
-
Use the Matrix package5m 29s
-
Create a sparse matrix4m 21s
-
Sparse matrices, triangles, and more6m 25s
-
Bootstrap analysis with R6m 8s
-
checkUsage4m 41s
-
-
-
Use R on the Raspberry Pi7m 32s
-
list2df()4m 28s
-
Introduction to clustering2m 23s
-
Clustering with kmeans6m 57s
-
Clustering with pam and clara6m 23s
-
Understanding silhouette graphs8m 39s
-
Clustering with fanny5m 23s
-
Clustering with hclust5m 12s
-
Clustering with agnes6m 22s
-
Clustering with diana4m 20s
-
cutree and identify with hclust4m 15s
-
Clustering with mona4m 31s
-
Clustering: dist vs. daisy4m 32s
-
-
-
Parameterized R markdown3m 42s
-
Run R on a schedule2m 53s
-
The new forward pipe operator3m 56s
-
Backslash lambda functions5m 24s
-
Dist() in depth5m 29s
-
Scale()3m 9s
-
toJSON4m 6s
-
fromJSON3m 48s
-
Validate JSON2m 28s
-
Plotmath and expression2m 24s
-
Run R in batch mode5m 40s
-
Explore music3m 49s
-
BEEP2m 3s
-
-
-
install.packages4m 27s
-
old.packages, new.packages, and update.packages2m 44s
-
library and require5m 32s
-
Excel in R: SUM5m 51s
-
Excel in R: IF6m 12s
-
Excel in R: LOOKUP5m 17s
-
Excel in R: LEFT and RIGHT4m 15s
-
Excel in R: MATCH4m 50s
-
Excel in R: CHOOSE4m 46s
-
Excel in R: DATE4m 8s
-
Excel in R: DAYS3m 55s
-
Excel in R: FIND and FINDB3m 9s
-
-
-
Excel in R: INDEX2m 28s
-
Excel in R: COUNT4m 5s
-
Excel in R: AVERAGE6m 39s
-
Excel in R: SUMIF and AVERAGEIF5m 17s
-
Excel in R: COUNTIF4m 48s
-
Excel in R: CONCATENATE4m 23s
-
Excel in R: MAX and MIN6m 56s
-
Excel in R: PROPER4m 28s
-
Excel in R: AND6m 58s
-
Excel in R: LEN3m 57s
-
Excel in R: COUNTA6m 28s
-
Excel in R: NETWORKDAYS6m 59s
-
Excel in R: IFERROR6m 27s
-
-
-
Introduction to Plumber6m 5s
-
Plumber request and response objects6m 43s
-
getwd setwd4m 24s
-
Use Visual Studio Code with R4m 34s
-
Tibbles4m 37s
-
Overview of dplyr4m 52s
-
dplyr: mutate6m 3s
-
dplyr: select4m 18s
-
dplyr: filter2m 27s
-
dplyr: slice and friends2m 59s
-
dplyr: summarise2m 55s
-
dplyr: arrange1m 43s
-
dplyr: group_by2m 34s
-
-
-
dbplyr translates R to SQL5m 14s
-
dplyr: pull4m 41s
-
dplyr: joins3m 50s
-
R7 OOP: Introduction6m 7s
-
R7 OOP: Properties4m 27s
-
R7 OOPS: Property getters and setters5m 38s
-
R7 OOPS: Validators3m 22s
-
R7 OOP: Class Inheritance3m 36s
-
R7 OOP: Generics and Methods6m 39s
-
Python with RStudio5m 12s
-
Animating plots3m 1s
-
Animating ggplot4m 3s
-
Introduction to Quarto6m 50s
-