compare_df.Rd
Obtain differences between two data frames
compare_df(dfcomp_x, dfcomp_y, keys_x, keys_y = NA, compare_values = FALSE)
dfcomp_x | first data frame to compare |
---|---|
dfcomp_y | second data frame to compare |
keys_x | keys of the first dataframe |
keys_y | (optional) keys of the second dataframe, if missing both data frames will be compared with the keys_x |
compare_values | (optional) if TRUE it will not only compare keys, but also will check if the values of non-key matching columns have the same values |
Differences and coincident values
data(heart_disease) a=heart_disease b=heart_disease a=subset(a, age >45) b=subset(b, age <50) b$gender='male' b$chest_pain=ifelse(b$chest_pain ==3, 4, b$chest_pain) res=compare_df(a, b, c('age', 'gender'))#>#>#># Print the keys that didn't match res#> $coincident #> age gender #> 67 46 male #> 68 46 male #> 69 46 male #> 70 46 male #> 71 46 male #> 72 46 male #> 73 46 male #> 74 46 male #> 75 46 male #> 76 46 male #> 77 46 male #> 78 46 male #> 79 46 male #> 80 46 male #> 81 46 male #> 82 46 male #> 83 46 male #> 84 46 male #> 85 46 male #> 86 46 male #> 87 46 male #> 88 46 male #> 89 46 male #> 90 46 male #> 91 46 male #> 92 46 male #> 93 46 male #> 94 46 male #> 95 47 male #> 96 47 male #> 97 47 male #> 98 47 male #> 99 47 male #> 100 47 male #> 101 47 male #> 102 47 male #> 103 47 male #> 104 47 male #> 105 47 male #> 106 47 male #> 107 47 male #> 108 47 male #> 109 47 male #> 110 47 male #> 111 47 male #> 112 47 male #> 113 47 male #> 114 47 male #> 115 47 male #> 116 47 male #> 117 47 male #> 118 47 male #> 119 47 male #> 121 48 male #> 122 48 male #> 123 48 male #> 124 48 male #> 125 48 male #> 126 48 male #> 127 48 male #> 128 48 male #> 129 48 male #> 130 48 male #> 131 48 male #> 132 48 male #> 133 48 male #> 134 48 male #> 135 48 male #> 136 48 male #> 137 48 male #> 138 48 male #> 139 48 male #> 140 48 male #> 141 48 male #> 142 48 male #> 143 48 male #> 144 48 male #> 145 48 male #> 146 48 male #> 147 48 male #> 148 48 male #> 149 48 male #> 150 48 male #> 151 48 male #> 152 48 male #> 153 48 male #> 154 48 male #> 155 48 male #> 156 48 male #> 157 48 male #> 158 48 male #> 159 48 male #> 160 48 male #> 161 48 male #> 162 48 male #> 165 49 male #> 166 49 male #> 167 49 male #> 168 49 male #> 169 49 male #> 170 49 male #> 171 49 male #> 172 49 male #> 173 49 male #> 174 49 male #> 175 49 male #> 176 49 male #> 177 49 male #> 178 49 male #> 179 49 male #> #> $rows_not_in_X #> age gender #> 1 29 male #> 2 34 male #> 3 34 male #> 4 35 male #> 5 35 male #> 6 35 male #> 7 35 male #> 8 37 male #> 9 37 male #> 10 38 male #> 11 38 male #> 12 39 male #> 13 39 male #> 14 39 male #> 15 39 male #> 16 40 male #> 17 40 male #> 18 40 male #> 19 41 male #> 20 41 male #> 21 41 male #> 22 41 male #> 23 41 male #> 24 41 male #> 25 41 male #> 26 41 male #> 27 41 male #> 28 41 male #> 29 42 male #> 30 42 male #> 31 42 male #> 32 42 male #> 33 42 male #> 34 42 male #> 35 42 male #> 36 42 male #> 37 43 male #> 38 43 male #> 39 43 male #> 40 43 male #> 41 43 male #> 42 43 male #> 43 43 male #> 44 43 male #> 45 44 male #> 46 44 male #> 47 44 male #> 48 44 male #> 49 44 male #> 50 44 male #> 51 44 male #> 52 44 male #> 53 44 male #> 54 44 male #> 55 44 male #> 56 45 male #> 57 45 male #> 58 45 male #> 59 45 male #> 60 45 male #> 61 45 male #> 62 45 male #> 63 45 male #> #> $rows_not_in_Y #> age gender #> 64 46 female #> 65 46 female #> 66 46 female #> 120 48 female #> 163 49 female #> 164 49 female #> 180 50 female #> 181 50 female #> 182 50 female #> 183 50 male #> 184 50 male #> 185 50 male #> 186 50 male #> 187 51 female #> 188 51 female #> 189 51 female #> 190 51 female #> 191 51 male #> 192 51 male #> 193 51 male #> 194 51 male #> 195 51 male #> 196 51 male #> 197 51 male #> 198 51 male #> 199 52 female #> 200 52 male #> 201 52 male #> 202 52 male #> 203 52 male #> 204 52 male #> 205 52 male #> 206 52 male #> 207 52 male #> 208 52 male #> 209 52 male #> 210 52 male #> 211 52 male #> 212 53 female #> 213 53 female #> 214 53 female #> 215 53 male #> 216 53 male #> 217 53 male #> 218 53 male #> 219 53 male #> 220 54 female #> 221 54 female #> 222 54 female #> 223 54 female #> 224 54 female #> 225 54 male #> 226 54 male #> 227 54 male #> 228 54 male #> 229 54 male #> 230 54 male #> 231 54 male #> 232 54 male #> 233 54 male #> 234 54 male #> 235 54 male #> 236 55 female #> 237 55 female #> 238 55 female #> 239 55 female #> 240 55 male #> 241 55 male #> 242 55 male #> 243 55 male #> 244 56 female #> 245 56 female #> 246 56 female #> 247 56 male #> 248 56 male #> 249 56 male #> 250 56 male #> 251 56 male #> 252 56 male #> 253 56 male #> 254 56 male #> 255 57 female #> 256 57 female #> 257 57 female #> 258 57 female #> 259 57 male #> 260 57 male #> 261 57 male #> 262 57 male #> 263 57 male #> 264 57 male #> 265 57 male #> 266 57 male #> 267 57 male #> 268 57 male #> 269 57 male #> 270 57 male #> 271 57 male #> 272 58 female #> 273 58 female #> 274 58 female #> 275 58 female #> 276 58 female #> 277 58 female #> 278 58 male #> 279 58 male #> 280 58 male #> 281 58 male #> 282 58 male #> 283 58 male #> 284 58 male #> 285 58 male #> 286 58 male #> 287 58 male #> 288 58 male #> 289 58 male #> 290 58 male #> 291 59 female #> 292 59 male #> 293 59 male #> 294 59 male #> 295 59 male #> 296 59 male #> 297 59 male #> 298 59 male #> 299 59 male #> 300 59 male #> 301 59 male #> 302 59 male #> 303 59 male #> 304 59 male #> 305 60 female #> 306 60 female #> 307 60 female #> 308 60 female #> 309 60 female #> 310 60 male #> 311 60 male #> 312 60 male #> 313 60 male #> 314 60 male #> 315 60 male #> 316 60 male #> 317 61 female #> 318 61 female #> 319 61 male #> 320 61 male #> 321 61 male #> 322 61 male #> 323 61 male #> 324 61 male #> 325 62 female #> 326 62 female #> 327 62 female #> 328 62 female #> 329 62 female #> 330 62 female #> 331 62 female #> 332 62 male #> 333 62 male #> 334 62 male #> 335 62 male #> 336 63 female #> 337 63 female #> 338 63 female #> 339 63 female #> 340 63 female #> 341 63 male #> 342 63 male #> 343 63 male #> 344 63 male #> 345 64 female #> 346 64 female #> 347 64 female #> 348 64 male #> 349 64 male #> 350 64 male #> 351 64 male #> 352 64 male #> 353 64 male #> 354 64 male #> 355 65 female #> 356 65 female #> 357 65 female #> 358 65 female #> 359 65 male #> 360 65 male #> 361 65 male #> 362 65 male #> 363 66 female #> 364 66 female #> 365 66 female #> 366 66 male #> 367 66 male #> 368 66 male #> 369 66 male #> 370 67 female #> 371 67 female #> 372 67 female #> 373 67 male #> 374 67 male #> 375 67 male #> 376 67 male #> 377 67 male #> 378 67 male #> 379 68 female #> 380 68 male #> 381 68 male #> 382 68 male #> 383 69 female #> 384 69 male #> 385 69 male #> 386 70 male #> 387 70 male #> 388 70 male #> 389 70 male #> 390 71 female #> 391 71 female #> 392 71 female #> 393 74 female #> 394 76 female #> 395 77 male #># Accessing the keys not present in the first data frame res[[1]]$rows_not_in_X#> NULL# Accessing the keys not present in the second data frame res[[1]]$rows_not_in_Y#> NULL# Accessing the keys which coincide completely res[[1]]$coincident#> NULL# Accessing the rows whose values did not coincide res[[1]]$different_values#> NULL