SlideShare a Scribd company logo
Manipulationg
   data in
    2013-02-22 @HSPH
   Kazuki Yoshida, M.D.
     MPH-CLE student

                          FREEDOM
                          TO	
  KNOW
Manipulating data in R

n   What are Objects?
n   What is Class attribute?
n   Various data objects you will see in R.
Objects

n   Just about everything named in R is an object
n   An object is a container that
     n   knows its class (label for what’s inside).
     n   has contents (eg, Actual numbers).
Examples of objects
n   dataset, which you use for analysis (various
     classes)
n   functions, which perform analysis (function class)
n   results, which come out of analysis (various
     classes)
     n   In effect, you always get a new dataset filled
          with results when you analyze data.
Classes of data values
      inside data objects
n   Numeric: Continuous variables
n   Factor: Categorical variables
n   Logical: TRUE/FALSE binary variables
n   etc...
Class?

n   An object’s class tells R how the object should be
     handled.
n   For example, summarizing data should work
     differently for numbers and categories!
Object




                                  iables
                              var
                          ical !
                       gor ide
                  C ate ins

                                Class attribute

    http://en.wikipedia.org/wiki/File:3_D-Box.jpg
Data objects

n   Vector (contains single class of data values)


n   List (contains multiple classes of data values)
Data objects

n   Vector (contains single class of data values)
     n   Array including Matrix
n   List (contains multiple classes of data values)
     n   Data frame
Vector
n   Smallest building block of data objects
n   Single dimension
n   Combination of values of same class
n   vec1 <- c(2013, 2, 15, -10) # combine
n   vec2 <- 1:16 # integers 1 to 16
Vector




1-dimensional
Array/Matrix
n   Vector folded into a multidimensional structure
n   2-dimensional array is a matrix
n   vec3 <- 1:16
n   dim(vec3) <- c(4, 4) # 4 x 4 structure
n   dim(vec3) <- c(2, 2, 4) # 2 x 2 x 4 structure
n   arr1 <- array(1:60, dim = c(3,4,5))
Matrix




Folded vector with dimension
List
n   Combination of any values or objects
n   Can contain objects of multiple classes
n   eg, a list of two vectors, a matrix, three arrays
n   List_name$Variable_name operation with $ operator
n   list1 <- list(first = 1:17, second = matrix(letters, 13,2))
n   list2 <- list(alpha = c(1,4,5,7), beta = c("h","s","p","h"))
List
           Multi-part object




  Can contain vectors,
    arrays, or lists!
Data frame
n   Special case of a list
n   List of same-length vectors vertically aligned
n   df1 <- data.frame(list2)
n   list3 <- list(small = letters, large = LETTERS,
     number = 1:26)
n   df2 <- data.frame(list3)
Data Frame




Multiple vectors of same length tied together!
Access by indexes
n   letters[3] # 1-dimensional object
n   arr1[1,2,3] # 3-dimensional object
n   arr1[1, ,3] # implies 1,(all),3
n   df1[ ,3] # implies (all),3
n   list1[[1]] # list needs [[ ]]
Access named elements
n   list3
n   list3$small
n   list3[["small"]]
n   df1$large
n   df1[, "large"]
20130222 Data structures and manipulation in R

More Related Content

PDF
20130215 Reading data into R
PDF
Reading Data into R
PDF
Data Structures
PPTX
Introduction To R Language
PPT
L6 structure
PPTX
Introduction To Data Structures.
PPT
Introduction to data structure by anil dutt
PPTX
DATA STRUCTURE
20130215 Reading data into R
Reading Data into R
Data Structures
Introduction To R Language
L6 structure
Introduction To Data Structures.
Introduction to data structure by anil dutt
DATA STRUCTURE

What's hot (20)

PDF
Data structure using c++
PPTX
Data structure & its types
PDF
Data Structures Notes 2021
PPTX
Mca ii dfs u-1 introduction to data structure
PPTX
Data structure power point presentation
PPTX
Data structure and its types
PDF
2nd puc computer science chapter 3 data structures 1
PDF
Introduction of data structures and algorithms
PPT
Data structures using C
PDF
Data structure
PPTX
PPTX
Bca ii dfs u-1 introduction to data structure
PPTX
Introduction of Data Structure
PDF
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & Preparation
PPTX
Introduction to data structure
PDF
R training2
PPT
Data structures using c
PDF
Elementary data structure
PPT
Lecture 1 data structures and algorithms
PPTX
Data structure and its types.
Data structure using c++
Data structure & its types
Data Structures Notes 2021
Mca ii dfs u-1 introduction to data structure
Data structure power point presentation
Data structure and its types
2nd puc computer science chapter 3 data structures 1
Introduction of data structures and algorithms
Data structures using C
Data structure
Bca ii dfs u-1 introduction to data structure
Introduction of Data Structure
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & Preparation
Introduction to data structure
R training2
Data structures using c
Elementary data structure
Lecture 1 data structures and algorithms
Data structure and its types.
Ad

Similar to 20130222 Data structures and manipulation in R (20)

PPTX
R data types
PPTX
R교육1
PDF
2 data structure in R
PDF
8074.pdf
PDF
DS Complete notes for Computer science and Engineering
PDF
Lecture20 vector
DOCX
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
PPTX
Abstract Algebra and Category Theory
PPT
array.ppt
PPT
Array.ppt
PDF
Introduction to R
PPTX
Array ppt
PDF
Array.pdf
PDF
Statistics lab 1
PPTX
Arrays And Pointers in C programming language
PPT
IR-ranking
PDF
M v bramhananda reddy dsa complete notes
PPTX
DSA Unit II array.pptx
PPTX
arrayppt.pptx
PDF
cluod.pdf
R data types
R교육1
2 data structure in R
8074.pdf
DS Complete notes for Computer science and Engineering
Lecture20 vector
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Abstract Algebra and Category Theory
array.ppt
Array.ppt
Introduction to R
Array ppt
Array.pdf
Statistics lab 1
Arrays And Pointers in C programming language
IR-ranking
M v bramhananda reddy dsa complete notes
DSA Unit II array.pptx
arrayppt.pptx
cluod.pdf
Ad

More from Kazuki Yoshida (20)

PDF
Graphical explanation of causal mediation analysis
PPTX
Pharmacoepidemiology Lecture: Designing Observational CER to Emulate an RCT
PDF
What is the Expectation Maximization (EM) Algorithm?
PDF
Propensity Score Methods for Comparative Effectiveness Research with Multiple...
PDF
Emacs Key Bindings
PDF
Visual Explanation of Ridge Regression and LASSO
PDF
ENAR 2018 Matching Weights to Simultaneously Compare Three Treatment Groups: ...
PDF
Search and Replacement Techniques in Emacs: avy, swiper, multiple-cursor, ag,...
PDF
Comparison of Privacy-Protecting Analytic and Data-sharing Methods: a Simulat...
PDF
Spacemacs: emacs user's first impression
PDF
Matching Weights to Simultaneously Compare Three Treatment Groups: a Simulati...
PDF
Multiple Imputation: Joint and Conditional Modeling of Missing Data
PDF
Linear regression with R 2
PDF
Linear regression with R 1
PDF
(Very) Basic graphing with R
PDF
Introduction to Deducer
PDF
Groupwise comparison of continuous data
PDF
Categorical data with R
PDF
Install and Configure R and RStudio
PDF
Reading Data into R REVISED
Graphical explanation of causal mediation analysis
Pharmacoepidemiology Lecture: Designing Observational CER to Emulate an RCT
What is the Expectation Maximization (EM) Algorithm?
Propensity Score Methods for Comparative Effectiveness Research with Multiple...
Emacs Key Bindings
Visual Explanation of Ridge Regression and LASSO
ENAR 2018 Matching Weights to Simultaneously Compare Three Treatment Groups: ...
Search and Replacement Techniques in Emacs: avy, swiper, multiple-cursor, ag,...
Comparison of Privacy-Protecting Analytic and Data-sharing Methods: a Simulat...
Spacemacs: emacs user's first impression
Matching Weights to Simultaneously Compare Three Treatment Groups: a Simulati...
Multiple Imputation: Joint and Conditional Modeling of Missing Data
Linear regression with R 2
Linear regression with R 1
(Very) Basic graphing with R
Introduction to Deducer
Groupwise comparison of continuous data
Categorical data with R
Install and Configure R and RStudio
Reading Data into R REVISED

20130222 Data structures and manipulation in R

  • 1. Manipulationg data in 2013-02-22 @HSPH Kazuki Yoshida, M.D. MPH-CLE student FREEDOM TO  KNOW
  • 2. Manipulating data in R n What are Objects? n What is Class attribute? n Various data objects you will see in R.
  • 3. Objects n Just about everything named in R is an object n An object is a container that n knows its class (label for what’s inside). n has contents (eg, Actual numbers).
  • 4. Examples of objects n dataset, which you use for analysis (various classes) n functions, which perform analysis (function class) n results, which come out of analysis (various classes) n In effect, you always get a new dataset filled with results when you analyze data.
  • 5. Classes of data values inside data objects n Numeric: Continuous variables n Factor: Categorical variables n Logical: TRUE/FALSE binary variables n etc...
  • 6. Class? n An object’s class tells R how the object should be handled. n For example, summarizing data should work differently for numbers and categories!
  • 7. Object iables var ical ! gor ide C ate ins Class attribute http://en.wikipedia.org/wiki/File:3_D-Box.jpg
  • 8. Data objects n Vector (contains single class of data values) n List (contains multiple classes of data values)
  • 9. Data objects n Vector (contains single class of data values) n Array including Matrix n List (contains multiple classes of data values) n Data frame
  • 10. Vector n Smallest building block of data objects n Single dimension n Combination of values of same class n vec1 <- c(2013, 2, 15, -10) # combine n vec2 <- 1:16 # integers 1 to 16
  • 12. Array/Matrix n Vector folded into a multidimensional structure n 2-dimensional array is a matrix n vec3 <- 1:16 n dim(vec3) <- c(4, 4) # 4 x 4 structure n dim(vec3) <- c(2, 2, 4) # 2 x 2 x 4 structure n arr1 <- array(1:60, dim = c(3,4,5))
  • 14. List n Combination of any values or objects n Can contain objects of multiple classes n eg, a list of two vectors, a matrix, three arrays n List_name$Variable_name operation with $ operator n list1 <- list(first = 1:17, second = matrix(letters, 13,2)) n list2 <- list(alpha = c(1,4,5,7), beta = c("h","s","p","h"))
  • 15. List Multi-part object Can contain vectors, arrays, or lists!
  • 16. Data frame n Special case of a list n List of same-length vectors vertically aligned n df1 <- data.frame(list2) n list3 <- list(small = letters, large = LETTERS, number = 1:26) n df2 <- data.frame(list3)
  • 17. Data Frame Multiple vectors of same length tied together!
  • 18. Access by indexes n letters[3] # 1-dimensional object n arr1[1,2,3] # 3-dimensional object n arr1[1, ,3] # implies 1,(all),3 n df1[ ,3] # implies (all),3 n list1[[1]] # list needs [[ ]]
  • 19. Access named elements n list3 n list3$small n list3[["small"]] n df1$large n df1[, "large"]