R
SINGLE MODE
DATA STRUCTURES
kensights@outlook.com
INTRODUCTION
• Standard modes/types of data in R
• Numeric
• Double e.g. 2.3, 2.3e3, 2.3E3, 2.3E-2,
• Integer e.g. 23, -23
• Complex e.g. 2.3+3.2E2i
• Logical e.g. TRUE, FALSE, T, F
• Character e.g. “Hello”, ‘Hello’
• mode(): returns the mode of an object
• mode<-: sets the mode of an object is conversion function is available
• Single Mode Containers / Data Structures
• Vectors
• Matrices
• Arrays
VECTORS
• Definition
• Container for storing a series of values of same mode
• Fundamental data element - R scalars are vectors of length 1
• Creation
• Combine function
• Sequence operator x:y
• Sequence function
• seq(x, y, s)
• x, y, s can be double or integer (positive / negative)
• Repeat function
• rep(x, n)
VECTORS
• Attributes
• Length
• Names
• Mode
VECTORS
• Subscripting or Referencing
• VECTOR[index specification]
• VECTOR[index specification] <- value
• Specification
• Blank [] : all elements
• Positive integers: keep those elements
• Negative integers: drop those elements return rest
• Logical: keep only those which are TRUE in position
• Character: keep whose names are specified
• LETTERS and letters:
• In built vectors for uppercase and lowercase English alphabets
MATRICES
• Definition
• Container for storing a 2D (rows x columns) values of same mode
• Creation
• Combine series of vectors column or row wise with recycling
• Using matrix function
• Fills column wise
• By Row
• Attributes
• Mode
• Length – all elements
• Number of rows
• Number of columns
• Dimensions
• Dimension Names
MATRICES
• Subscripting or Referencing
• MATRIX[row index, col index]
• MATRIX[row index, col index] <- value
• Specification
• Blank [] : all elements
• Positive integers: keep those elements
• Negative integers: drop those elements return rest
• Logical: keep only those which are TRUE in position
• Character: keep whose names are specified
• Preserving Dimensions of matrix subset
• When one row or one column is returned the dimensions are dropped and a vector is returned
• To preserve dimensions use drop = FALSE option
MATRICES
• Logical Subscripting or Referencing
• Using dimension names
• Subscripting using row index only
• Returns a vector
• Subscripting as if the matrix is a vector
ARRAYS
• Definition
• Container for storing values of same mode any number of dimensions
• Creation
• Array function with dimensions
• Attributes
• Mode
• Length – all elements
• Dimensions
• Dimension Names
ARRAYS
• Subscripting or Referencing
• ARRAY[dim1 index, dim2 index, dim3 index…]
• ARRAY[dim1 index, dim2 index, dim3 index…] <- value
• Specification
• Blank [] : all elements
• Positive integers: keep those elements
• Negative integers: drop those elements return rest
• Logical: keep only those which are TRUE in position
• Character: keep whose names are specified
• Preserving Dimensions of array subset
• When one row or one column is returned the dimensions are dropped and a vector or matrix is
returned
• To preserve dimensions use drop = FALSE option
END NOTES
• Matrices and arrays are essentially vectors with dimensions
• Thus they can be morphed into one another

R DATA STRUCTURES 1

  • 1.
  • 2.
    INTRODUCTION • Standard modes/typesof data in R • Numeric • Double e.g. 2.3, 2.3e3, 2.3E3, 2.3E-2, • Integer e.g. 23, -23 • Complex e.g. 2.3+3.2E2i • Logical e.g. TRUE, FALSE, T, F • Character e.g. “Hello”, ‘Hello’ • mode(): returns the mode of an object • mode<-: sets the mode of an object is conversion function is available • Single Mode Containers / Data Structures • Vectors • Matrices • Arrays
  • 3.
    VECTORS • Definition • Containerfor storing a series of values of same mode • Fundamental data element - R scalars are vectors of length 1 • Creation • Combine function • Sequence operator x:y • Sequence function • seq(x, y, s) • x, y, s can be double or integer (positive / negative) • Repeat function • rep(x, n)
  • 4.
  • 5.
    VECTORS • Subscripting orReferencing • VECTOR[index specification] • VECTOR[index specification] <- value • Specification • Blank [] : all elements • Positive integers: keep those elements • Negative integers: drop those elements return rest • Logical: keep only those which are TRUE in position • Character: keep whose names are specified • LETTERS and letters: • In built vectors for uppercase and lowercase English alphabets
  • 6.
    MATRICES • Definition • Containerfor storing a 2D (rows x columns) values of same mode • Creation • Combine series of vectors column or row wise with recycling • Using matrix function • Fills column wise • By Row • Attributes • Mode • Length – all elements • Number of rows • Number of columns • Dimensions • Dimension Names
  • 7.
    MATRICES • Subscripting orReferencing • MATRIX[row index, col index] • MATRIX[row index, col index] <- value • Specification • Blank [] : all elements • Positive integers: keep those elements • Negative integers: drop those elements return rest • Logical: keep only those which are TRUE in position • Character: keep whose names are specified • Preserving Dimensions of matrix subset • When one row or one column is returned the dimensions are dropped and a vector is returned • To preserve dimensions use drop = FALSE option
  • 8.
    MATRICES • Logical Subscriptingor Referencing • Using dimension names • Subscripting using row index only • Returns a vector • Subscripting as if the matrix is a vector
  • 9.
    ARRAYS • Definition • Containerfor storing values of same mode any number of dimensions • Creation • Array function with dimensions • Attributes • Mode • Length – all elements • Dimensions • Dimension Names
  • 10.
    ARRAYS • Subscripting orReferencing • ARRAY[dim1 index, dim2 index, dim3 index…] • ARRAY[dim1 index, dim2 index, dim3 index…] <- value • Specification • Blank [] : all elements • Positive integers: keep those elements • Negative integers: drop those elements return rest • Logical: keep only those which are TRUE in position • Character: keep whose names are specified • Preserving Dimensions of array subset • When one row or one column is returned the dimensions are dropped and a vector or matrix is returned • To preserve dimensions use drop = FALSE option
  • 11.
    END NOTES • Matricesand arrays are essentially vectors with dimensions • Thus they can be morphed into one another

Editor's Notes

  • #3 For effectively using R for gaining insights from data one needs to have working knowledge of the standard data types and data structures in R.
  • #4 For effectively using R for gaining insights from data one needs to have working knowledge of the standard data types and data structures in R.
  • #5 For effectively using R for gaining insights from data one needs to have working knowledge of the standard data types and data structures in R.
  • #6 For effectively using R for gaining insights from data one needs to have working knowledge of the standard data types and data structures in R.
  • #7 For effectively using R for gaining insights from data one needs to have working knowledge of the standard data types and data structures in R.
  • #8 For effectively using R for gaining insights from data one needs to have working knowledge of the standard data types and data structures in R.
  • #9 For effectively using R for gaining insights from data one needs to have working knowledge of the standard data types and data structures in R.
  • #10 For effectively using R for gaining insights from data one needs to have working knowledge of the standard data types and data structures in R.
  • #11 For effectively using R for gaining insights from data one needs to have working knowledge of the standard data types and data structures in R.
  • #12 For effectively using R for gaining insights from data one needs to have working knowledge of the standard data types and data structures in R.