Guest User

Untitled

a guest
Feb 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. df = read.csv('data.csv', stringsAsFactors = FALSE,
  2. colClasses = colClass,na.strings = c("NA", ""))
  3.  
  4. df = na.omit(df)
  5.  
  6. df <- df[!apply(df, 1, function(x){all(x=="")}),]
  7.  
  8. df <- df[complete.cases(df),]
  9.  
  10. df[is.na(df)] <- ""
  11.  
  12. # example data
  13. dat <- tribble(~col1, ~col2,
  14. 1, "",
  15. 2, "some string",
  16. 3, "another string")
  17. dat
  18. # A tibble: 3 x 2
  19. col1 col2
  20. <dbl> <chr>
  21. 1 1.00 ""
  22. 2 2.00 some string
  23. 3 3.00 another string
  24.  
  25. dat %>%
  26. na_if("") %>%
  27. na.omit()
  28. # A tibble: 2 x 2
  29. col1 col2
  30. <dbl> <chr>
  31. 1 2.00 some string
  32. 2 3.00 another string
Add Comment
Please, Sign In to add comment