How to Merge Two Unequal Data Frames & Replace NA with 0 in R (Example) | merge & is.na Functions

Published: 16 November 2020
on channel: Statistics Globe
4,118
52

How to combine unequal data frames and replace missing data with zero in the R programming language. More details: https://statisticsglobe.com/merge-une...
R code of this video:

data1 <- data.frame(id = 1:5, # Create first data frame
x1 = 5:9,
x2 = 5:1)

data2 <- data.frame(id = 3:7, # Create second data frame
y1 = 20:24,
y2 = 10:14)

data_all <- merge(data1, data2, # Merge data
by = "id",
all = TRUE)

data_all[is.na(data_all)] <- 0 # Replace NA with 0

Follow me on Social Media:
Twitter:   / joachimschork  
Facebook:   / statisticsglobecom  
Reddit:   / joachimschork  
Pinterest: https://www.pinterest.de/JoachimSchork


Watch video How to Merge Two Unequal Data Frames & Replace NA with 0 in R (Example) | merge & is.na Functions online without registration, duration hours minute second in high quality. This video was added by user Statistics Globe 16 November 2020, don't forget to share it with your friends and acquaintances, it has been viewed on our site 4,118 once and liked it 52 people.