2.3 Create Vectors With Patterns | R Programming: Zero To Pro

  • R Programming: Zero to Pro
  • Preface
  • Contributing to the Book
    • Typos or Grammar Issues
    • General Questions or Feedback
  • Acknowledgement
  • Building Environment
  • 1 Introduction
    • 1.1 Installation of R, RStudio and R Packages
      • 1.1.1 Download and Install
      • 1.1.2 RStudio Interface
      • 1.1.3 Install and load R packages
      • 1.1.4 Exercises
    • 1.2 Use R as a Fancy Calculator
      • 1.2.1 Add comments using “#”
      • 1.2.2 Basic calculation
      • 1.2.3 Get help in R
      • 1.2.4 Approximation
      • 1.2.5 Power & logarithm
      • 1.2.6 Trigonometric function
      • 1.2.7 Exercises
    • 1.3 Object Assignment
      • 1.3.1 What is an R Object?
      • 1.3.2 Assignment Operation with <-
      • 1.3.3 Object Naming Rules
      • 1.3.4 Review objects in environment
      • 1.3.5 Object types
      • 1.3.6 Exercises
  • 2 R Objects (I): Atomic Vectors
    • 2.1 Introduction to Numeric Vectors
      • 2.1.1 Creation and class
      • 2.1.2 Operations and recycling rule
      • 2.1.3 Storage types (doubles and integers)
      • 2.1.4 Printing
      • 2.1.5 Exercises
    • 2.2 Introduction to Character Vectors
      • 2.2.1 Creation, class and storage type
      • 2.2.2 Change case
      • 2.2.3 Review of getting help in R
      • 2.2.4 Exercises
    • 2.3 Introduction to Logical Vectors
      • 2.3.1 Logical vectors: creation by comparisons, class, and storage type
      • 2.3.2 Logical vectors: creation when testing for types
      • 2.3.3 Exercises
    • 2.4 Coercion Rule
      • 2.4.1 Coercion with c()
      • 2.4.2 Coercion in operators
      • 2.4.3 Explicit Coercion
      • 2.4.4 Exercises
    • 2.5 Vector Subsetting and Modifying Values
      • 2.5.1 Named Vectors
      • 2.5.2 Vector subsetting
      • 2.5.3 Access and modify values in vectors and sub-vectors
      • 2.5.4 Exercises
    • 2.6 Numeric Vectors: Creating numeric vectors with patterns
      • 2.6.1 The colon operator : – Equally-spaced numeric vectors with increment of 1 or -1
      • 2.6.2 The seq() function – Equally-spaced numeric vectors with any increment
      • 2.6.3 The sequence generator seq_along() – Matching numeric vectors
      • 2.6.4 The rep() Function – Numeric vectors with repeated values
      • 2.6.5 The unique() and table() Functions – Getting unique elements and their frequencies
      • 2.6.6 Exercises
    • 2.7 Numeric Vectors: Sort, Rank, Order
      • 2.7.1 Sort vectors with sort()
      • 2.7.2 Get ranks in vectors with rank()
      • 2.7.3 Get the ordering permutation via `order()
      • 2.7.4 Exercises
    • 2.8 Numeric vector: Summary Statistics
      • 2.8.1 Minimum and Maximum
      • 2.8.2 Sum and Product
      • 2.8.3 Mean and median
      • 2.8.4 Quantiles
      • 2.8.5 Summary statistics
      • 2.8.6 Exercises
    • 2.9 Character Vectors: Create with Repetition and Concatenate
      • 2.9.1 Create character vectors with repetition
      • 2.9.2 Concatenate strings with paste()
      • 2.9.3 Output via cat()
      • 2.9.4 Exercises
    • 2.10 Character Vectors: Sort, Rank, Order
      • 2.10.1 Ordering rules
      • 2.10.2 Sort vectors with sort()
      • 2.10.3 Get ranks in vectors with rank()
      • 2.10.4 Get the ordering permutation via order()
      • 2.10.5 Summary and comparisons
      • 2.10.6 Exercises
    • 2.11 Character Vectors, Factors & Ordered Factors
      • 2.11.1 Create a factor from a vector
      • 2.11.2 Set the factor levels and labels
      • 2.11.3 Ordered factors
      • 2.11.4 Exercises
    • 2.12 Logical Vectors: Create with Repetitions and Summary Functions
      • 2.12.1 Create logical vectors with repetitions
      • 2.12.2 Statistical Functions on Logical Vectors
      • 2.12.3 Exercises
    • 2.13 Logical Vectors: Logical Operators
      • 2.13.1 NOT operator by !
      • 2.13.2 AND operator by &
      • 2.13.3 OR operator by |
      • 2.13.4 Exclusive OR by xor
      • 2.13.5 Summary of Logical Operators
      • 2.13.6 Exercises
    • 2.14 Set Operations on Vectors
      • 2.14.1 Set operations on vectors
      • 2.14.2 Applicance of the coercion rule
      • 2.14.3 Summary
      • 2.14.4 Exercises
    • 2.15 Missing Values (NA)
      • 2.15.1 NA and NaN are contagious
      • 2.15.2 Work with NA values
      • 2.15.3 Exercises
    • 2.16 Dates and Times
      • 2.16.1 Dates
      • 2.16.2 Times
      • 2.16.3 Exercises
    • 2.17 Other Atomic Vector Types
      • 2.17.1 Complex Vectors
      • 2.17.2 Raw Vectors
      • 2.17.3 Full Coercion Ordering
      • 2.17.4 Exercises
  • 3 R Objects (II): Other Types
    • 3.1 Matrix
      • 3.1.1 Create a matrix from a vector
      • 3.1.2 Combine vectors or matrices into a matrix
      • 3.1.3 Matrix subsetting
      • 3.1.4 Modify values in sub-matrices
      • 3.1.5 Operators and functions on matrices
      • 3.1.6 Apply functions on each row or each column
      • 3.1.7 Exercises
    • 3.2 Array
      • 3.2.1 Create an array from a vector
      • 3.2.2 Array subsetting
      • 3.2.3 Operators and functions on arrays
      • 3.2.4 Apply functions along certain dimension(s)
      • 3.2.5 Exercises
    • 3.3 Data Frame
      • 3.3.1 Introduction to Data Frames
      • 3.3.2 Adding Observations or Variables in Data Frames
      • 3.3.3 Subsetting and Modifying Data Frames
      • 3.3.4 Exercises
    • 3.4 Tibble
      • 3.4.1 Introduction to tibbles
      • 3.4.2 Adding Observations or Variables in Tibbles
      • 3.4.3 Tibble subsetting and modifying
      • 3.4.4 Exercises
    • 3.5 List
      • 3.5.1 Create a list
      • 3.5.2 Extract a list element and list subsetting
      • 3.5.3 List inside a list
      • 3.5.4 Unlist a list
      • 3.5.5 Apply functions for each element of a list
      • 3.5.6 List Matrix
      • 3.5.7 Exercises
    • 3.6 NULL, NaN, and Inf
      • 3.6.1 NULL
      • 3.6.2 NaN
      • 3.6.3 Inf
      • 3.6.4 A comparison of the four special values in R
      • 3.6.5 Exercises
    • 3.7 Summary of R Objects
      • 3.7.1 Exercises
  • 4 Data Import and Export
    • 4.1 Introduction to Data Sets
      • 4.1.1 Gapminder Data Set
      • 4.1.2 Small Ames Housing Price Data Set
      • 4.1.3 Converting Data Types
      • 4.1.4 Recover Modified Values
    • 4.2 Exporting Data to Delimited Files
      • 4.2.1 Set the working directory
      • 4.2.2 Delimited files
      • 4.2.3 Write an object into a .csv file
      • 4.2.4 Write an object into a general delimited file
      • 4.2.5 Exercises
    • 4.3 Importing Data from Delimited Files
      • 4.3.1 Import .csv Files using read_csv()
      • 4.3.2 Read Inline .csv Files
      • 4.3.3 Handling Missing Values
      • 4.3.4 Importing Data From a Delimited File
      • 4.3.5 Import Data Using the Menu
      • 4.3.6 Exercises
    • 4.4 Exporting to and Importing from Excel Files
      • 4.4.1 Export data into Excel files
      • 4.4.2 Import Excel Files (.xls and .xlsx ) using read_excel()
      • 4.4.3 Import Excel file using the menu
      • 4.4.4 Exercises
    • 4.5 Exporting to and Importing from SPSS, SAS, and Stata Files
      • 4.5.1 Export and Import SPSS Files
      • 4.5.2 Export and Import SAS Files
      • 4.5.3 Export and Import Stata Files
      • 4.5.4 Import using the menu
      • 4.5.5 Exercise
    • 4.6 Save and Restore Objects and Workspace
      • 4.6.1 Save and Restore Objects using .RData
      • 4.6.2 Save and Restore a Single Object using saveRDS() and readRDS()
      • 4.6.3 Exercises
  • 5 Basic Data Visualization
    • 5.1 Scatterplot
      • 5.1.1 Using the plot() function
      • 5.1.2 Interacting and Saving the plot from plot()
      • 5.1.3 Using the ggplot() function
      • 5.1.4 Interact and Save the plot from ggplot()
      • 5.1.5 Exercises
    • 5.2 ggplot Aesthetics (I): Constant-Valued Aesthetics
      • 5.2.1 Exercises
    • 5.3 ggplot Aesthetics (II): Local Aesthetics Mapping
      • 5.3.1 Basic Local Aesthetics Mapping
      • 5.3.2 Customize the Local Aesthetics Mapping
      • 5.3.3 Customize the legend order for discrete variables
      • 5.3.4 Create Logical Variables and Map to Aesthetics
      • 5.3.5 Exercises
    • 5.4 Customization in ggplot
      • 5.4.1 Customization of Labels and Titles
      • 5.4.2 Customizing the Breaks on the x and y Axes
      • 5.4.3 Zoom In to a Specific Region of the Data
      • 5.4.4 Generate Log-Scale Plot
      • 5.4.5 Coordinate Flip
      • 5.4.6 Exercises
    • 5.5 Line Plots
      • 5.5.1 Line Plots via plot()
      • 5.5.2 Line Plots via geom_line()
      • 5.5.3 Constant-Valued Aesthetics in Line Plots
      • 5.5.4 Mapping Variables to Aesthetics in Line Plots
      • 5.5.5 Exercises
    • 5.6 Smoothline Fits
      • 5.6.1 Creating Smoothline Fits using geom_smooth()
      • 5.6.2 Constant-Valued Aesthetics in Smoothline Fits
      • 5.6.3 Local Aesthetics Mapping in Smoothline Fits
      • 5.6.4 Exercises
    • 5.7 ggplot Aesthetics (III): Global Aesthetic Mapping
      • 5.7.1 Multiple geoms
      • 5.7.2 Global Aesthetic Mapping
      • 5.7.3 Exercises
    • 5.8 Bar Charts and Pie Charts via geom_bar()
      • 5.8.1 An Introduction to Bar Charts
      • 5.8.2 Reordering Bars in Bar Charts
      • 5.8.3 Aesthetics in Bar Charts
      • 5.8.4 Pie Charts
      • 5.8.5 Exercises
    • 5.9 Histograms
      • 5.9.1 Using the hist() function
      • 5.9.2 Using the geom_histogram() function
      • 5.9.3 Aesthetics in geom_histogram()
      • 5.9.4 Density Estimate Using Histograms
      • 5.9.5 Exercises
    • 5.10 Density Plots
      • 5.10.1 Aesthetics in Density Plots
      • 5.10.2 Exercises
    • 5.11 Boxplots
      • 5.11.1 Using the boxplot() function
      • 5.11.2 Using the geom_boxplot() function
      • 5.11.3 Compare distributions in different groups
      • 5.11.4 Aesthetics in Boxplots
      • 5.11.5 Notched Boxplots
      • 5.11.6 Exercises
    • 5.12 Arrange Multiple Plots
      • 5.12.1 Facet wrap
      • 5.12.2 Facet grid
      • 5.12.3 Exercises
    • 5.13 Review of Basic Visualization
      • 5.13.1 Summary of geoms
      • 5.13.2 The grammatical structure of ggplot()
      • 5.13.3 A complex ggplot() example
  • 6 Advanced Data Visualization
    • 6.1 Jitter and Count Plots
      • 6.1.1 Overplotting
      • 6.1.2 Jittering
      • 6.1.3 Counts Plots
      • 6.1.4 Exercises
    • 6.2 Violin Plots
      • 6.2.1 The basic violin plot
      • 6.2.2 Violin plot with boxplot
    • 6.3 Line Segments
      • 6.3.1 Using abline() with plot()
      • 6.3.2 Using geom_hline(), geom_vline() and geom_abline()
      • 6.3.3 Exercises
    • 6.4 Heat Map
      • 6.4.1 Using the heatmap() function
      • 6.4.2 Using geom_tile() in ggplot2
    • 6.5 Error Bars
    • 6.6 Interactive Plot with plotly()
  • 7 Data Manipulation
    • 7.1 Filter Observations, Objects Masking, and the Pipe
      • 7.1.1 Objects Masking
      • 7.1.2 Filter Observations
      • 7.1.3 The pipe operator
      • 7.1.4 Exercise
    • 7.2 Select, Rename, and Reorder Variables
      • 7.2.1 Select Variables via Names
      • 7.2.2 Rename Variables
      • 7.2.3 Select Variables with Patterns
      • 7.2.4 Reorder Variables via Names
      • 7.2.5 Exercise
    • 7.3 Reorder Observations
      • 7.3.1 Exercises
    • 7.4 Create New Variables via mutate() and transmute()
      • 7.4.1 Exercises
    • 7.5 Create Grouped Summaries via group_by() and summarize()
      • 7.5.1 Create Summaries
      • 7.5.2 Create Grouped Summaries
      • 7.5.3 Exercises
    • 7.6 Grouped Mutate and Filter via group_by()
      • 7.6.1 Grouped Filter
      • 7.6.2 Grouped Mutate
      • 7.6.3 Exercises
    • 7.7 Joins
      • 7.7.1 Inner Join
      • 7.7.2 Left Join
      • 7.7.3 Right Join
      • 7.7.4 Full Join
      • 7.7.5 Filtering Joins
      • 7.7.6 A Summary of All Joins
      • 7.7.7 Exercises
    • 7.8 Set Operations on Datasets
      • 7.8.1 intersect(x, y)
      • 7.8.2 union(x, y)
      • 7.8.3 union_all(x, y)
      • 7.8.4 setdiff(x, y)
      • 7.8.5 symdiff(x, y)
      • 7.8.6 setequal(x, y)
      • 7.8.7 Summary
      • 7.8.8 Exercises
  • 8 Tidy Data
    • 8.1 Convert Between Names and Values
      • 8.1.1 Convert Values into Column Names
      • 8.1.2 Convert Column Names into Values
      • 8.1.3 Multiple Variables
      • 8.1.4 Exercises
    • 8.2 Separate and Combine Columns via separate() and unite()
      • 8.2.1 Combine Columns via unite()
      • 8.2.2 Separate One Column into Multiple Columns Using separate()
      • 8.2.3 Exercises
    • 8.3 More on Missing Values
      • 8.3.1 Missing Values in Tidy Data
      • 8.3.2 Filling Missing Values
  • 9 Strings
    • 9.1 Concatenate and Subset Strings
      • 9.1.1 Concatenate Strings
      • 9.1.2 Create and Modify Substrings
      • 9.1.3 Exercises
    • 9.2 Matching Pattern with Regular Expressions
      • 9.2.1 Basic Pattern Matching
      • 9.2.2 Character Classes
      • 9.2.3 Combining Patterns with Logical Operators
      • 9.2.4 Conclusion
      • 9.2.5 Exercises
  • 10 Statistics
    • 10.1 Normal Distribution
      • 10.1.1 Probability Density Function (PDF)
      • 10.1.2 Cumulative Distribution Function (CDF)
      • 10.1.3 The Empirical Rule (68-95-99.7)
      • 10.1.4 Quantile Function
      • 10.1.5 Random Number Generator
      • 10.1.6 Exercises
    • 10.2 Other Distributions
      • 10.2.1 Discrete vs. Continuous Distributions
      • 10.2.2 Binomial Distribution
      • 10.2.3 Poisson Distribution
      • 10.2.4 Exponential Distribution
      • 10.2.5 A Summary of Commonly Used Distributions
      • 10.2.6 Exercise
    • 10.3 Random Permutation and Random Sampling
      • 10.3.1 Random Permutation
      • 10.3.2 Random Sampling Without Replacement
      • 10.3.3 Random Sampling with Replacement
      • 10.3.4 Random Sampling with Unequal Probabilities
      • 10.3.5 Exercise
    • 10.4 Multivariate Normal Distribution
      • 10.4.1 Generate Multivate Normal Distribution
      • 10.4.2 Properties of Multivariate Normal Distribution
      • 10.4.3 Sample Mean and Sample Covariance Matrix
      • 10.4.4 Sample Correlation Matrix
      • 10.4.5 Exercise
  • 11 Control Statements
    • 11.1 Conditional Statements via if, else, and switch()
      • 11.1.1 The Structure of Conditional Statements
      • 11.1.2 Example: Checking Even or Odd Numbers
      • 11.1.3 Using ifelse()
      • 11.1.4 Multiple Conditions with else if
      • 11.1.5 Using switch() for Multiple Choices
      • 11.1.6 Logical Operators in Conditional Statements
      • 11.1.7 Exercises
    • 11.2 Loops
      • 11.2.1 for loops with known sequence
      • 11.2.2 Combine the conditional statements with loops
      • 11.2.3 Control Loop Flow With next and break
      • 11.2.4 Nested Loops
      • 11.2.5 Nested Loop via the outer() Function
      • 11.2.6 Exercises
    • 11.3 While Loops and Repeat
      • 11.3.1 while loop
      • 11.3.2 repeat Loop
      • 11.3.3 Comparison of for, while, and repeat Loops
      • 11.3.4 Exercises
  • 12 Functions
    • 12.1 Introduction to Functions
      • 12.1.1 What are Functions?
      • 12.1.2 Syntax of a Function
      • 12.1.3 Default Arguments in Functions
      • 12.1.4 Project: Dice Simulation
      • 12.1.5 Project: Get Fibonacci Sequence
      • 12.1.6 Exercises
    • 12.2 Going Beyond Basics: Advanced R Functions
      • 12.2.1 Returning Multiple Values Using Lists
      • 12.2.2 Nested Functions
      • 12.2.3 Higher-Order Functions
      • 12.2.4 Error Handling in Functions
      • 12.2.5 Exercise
    • 12.3 Anonymous Functions and Scoping
      • 12.3.1 Anonymous Functions
      • 12.3.2 Advanced Use Cases for Anonymous Functions
      • 12.3.3 Scoping in R
      • 12.3.4 Exercises
  • 13 R Markdown
    • 13.1 Introduction to R Markdown
      • 13.1.1 Create a new R Markdown document
      • 13.1.2 Knit the R Markdown document
      • 13.1.3 Write an R Markdown document
    • 13.2 Text Formatting in R Markdown
      • 13.2.1 Headers: Your Document’s Signposts
      • 13.2.2 Emphasis: Making Your Point
      • 13.2.3 Inline Code: Displaying and Evaluating
      • 13.2.4 Lists: Ordered and Unordered
      • 13.2.5 Hyperlinks: Connecting to the World
      • 13.2.6 Blockquotes: Highlighting Wisdom
      • 13.2.7 Footnotes: Adding Extra Details
      • 13.2.8 The Language of the Universe: Writing Mathematics
      • 13.2.9 Tables: From Simple to Stunning
      • 13.2.10 Insert citations and manage bibliographies in R Markdown
      • 13.2.11 Your Turn: A Mini-Challenge
  • 14 A Case Study: 24 Game Solver
    • 14.1 Permutation and Operator Sequence
      • 14.1.1 Breaking Down a Solution
      • 14.1.2 Getting All Permutations
      • 14.1.3 Getting All Operators
    • 14.2 Composite Operators and Check Solution
      • 14.2.1 Composite Operators
      • 14.2.2 Check if Solution is Found
      • 14.2.3 Looping Over All Number Sequences and All Operator Sequences
    • 14.3 Solve 24
  • References
  • Published with bookdown
R Programming: Zero to Pro Page not found

The page you requested cannot be found (perhaps it was moved or renamed).

You may want to try searching to find the page's new location, or use the table of contents to find the page you are looking for.

Buy Me A Coffee

Tag » How To Create Vector In R