Menu
Newbedev LogoNEWBEDEV Python Javascript Linux Cheat sheet
Newbedev LogoNEWBEDEV
  • Python 1
  • Javascript
  • Linux
  • Cheat sheet
  • Contact

Sum of two Columns of Data Frame with NA Values

dplyr solution, taken from here:

library(dplyr)
dat %>% 
    rowwise() %>% 
    mutate(e = sum(b, c, na.rm = TRUE))

dat$e <- rowSums(dat[,c("b", "c")], na.rm=TRUE)
dat
#   a  b c d e
# 1 1  2 3 4 5
# 2 5 NA 7 8 7

Tags:

R

Related

Assigning 128 bit integer in C Using a different manifestPlaceholder for each Build Variant How do I unzip all files in a folder using 7-zip in batch? What does an HTTP 500 error with a 121 sub-status signify? How do I display 400,000 or more points in Openlayers 3 using less than 200MB of memory? Spark UI on AWS EMR Python calculating Catalan Numbers Linkedin rest api to search people with name Find element that is causing the showing of horizontal scrollbar in Google Chrome Is it possible to filter a jQuery DataTable by data attribute? Uncaught TypeError when calling drawImage function Visual Studio: MSB3073 error exited with code 1

Recent Posts

Pandas how to find column contains a certain value Recommended way to install multiple Python versions on Ubuntu 20.04 Build super fast web scraper with Python x100 than BeautifulSoup How to convert a SQL query result to a Pandas DataFrame in Python How to write a Pandas DataFrame to a .csv file in Python
© 2021 newbedevPrivacy Policy