2  Data Management

2.1 Differences

2.1.1 {waldo}

waldo::compare(c("a", "b", "c"), c("a", "b"))
`old`: "a" "b" "c"
`new`: "a" "b"    
df1 <- data.frame(x = 1:3, y = 3:1)
df2 <- tibble::tibble(rev(df1))
waldo::compare(df1, df2)
`class(old)`: "data.frame"                   
`class(new)`: "tbl_df"     "tbl" "data.frame"

`names(old)`: "x" "y"
`names(new)`: "y" "x"

2.1.2 Vector Item Difference

x <- c(1,2,3,4)
y <- c(2,3,4)
setdiff(x, y)
[1] 1

2.2 Quick Q&A

2.2.1 replacement for plyr::rbind.fill

dplyr::bind_rows()

2.2.2 Set colnames in pipe

df %>% `colnames<-` newnames
colnames(cars)
[1] "speed" "dist" 
cars |> `colnames<-`(c("one", "two")) |> head()
  one two
1   4   2
2   4  10
3   7   4
4   7  22
5   8  16
6   9  10

2.2.3 Remove Columns by Var Type

df[,-which(sapply(df, class) == "factor")]
df[, sapply(df, class) != "factor"]
df[,sapply(df, is.numeric)]