1 / 6

HMI 7530 – Programming in R DATA MANAGEMENT MODULE: Concatenating, Stacking and Merging

HMI 7530 – Programming in R DATA MANAGEMENT MODULE: Concatenating, Stacking and Merging. Jennifer Lewis Priestley, Ph.D. Kennesaw State University. DATA MANAGEMENT MODULE. Importing and Exporting Imputting data directly into R Creating, Adding and Dropping Variables Assigning objects

Download Presentation

HMI 7530 – Programming in R DATA MANAGEMENT MODULE: Concatenating, Stacking and Merging

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. HMI 7530 – Programming in R DATA MANAGEMENT MODULE: Concatenating, Stacking and Merging Jennifer Lewis Priestley, Ph.D. Kennesaw State University

  2. DATA MANAGEMENT MODULE • Importing and Exporting • Imputting data directly into R • Creating, Adding and Dropping Variables • Assigning objects • Subsetting and Formatting • Merging, Stacking and Recoding • Using SQL in R 2 2 2

  3. Data Management Module: Concatenating To “concatenate” basically means to bring together columns (vectors) of data. In R, this is accomplished through the function cbind: Newdata <- cbind(data1, data2) This will create as many columns are in the sum of data1 and data2. Note that a “matchkey” is not needed. 3

  4. Data Management Module: Stacking To “stack” basically means to bring together rows of data. In R, this is accomplished through the function rbind: Newdata <- rbind(data1, data2) This will create as many rows are in the sum of data1 and data2. Note that there MUST be the same column names in data1 and data2. Note that a “matchkey” is not needed. 4

  5. Data Management Module: Merging To “Merge” basically means to bring together dataframes. In R, this is accomplished through the function merge: Newdata <- merge (data1, data2, by="PrimaryKey", all="TRUE") Note that all = TRUE will include all rows and columns for both data1 and data2 – essentially an outer join. all=FALSE will include only rows and columns that are present in both data1 and data2 – essentially an inner join. Note that a “matchkey” IS needed. 5

  6. Data Management Module: Missing Values At this point, lets recode values using the same logic you would use in Excel: IF(Condition, value if true, value if false) In R: newvariable<-ifelse(oldvariable test, value if true, value if false) 6

More Related