Create new dataframe based on filter/select id from a dataframe

I have a database with 1000 rows. This database contains the id and name of the occupation for the year 2000 and the year 2010. I would like to create a new dataframe with the id and name of the occupations that were changed (the id, the name, or both were changed) and a dataframe with the id and name of the ones that have not changed. COuld you guys help me?
Here is a sample:

Data_Frame <- data.frame (
  title_2000 = c(" All Other Managers", "Industrial Production Managers", "Sales Managers", "Logistics Engineers", "Accountants and Auditors"),
  code_2000 = c("11-9199", "11-3051", "11-2022", "13-1081", "13-2011"),
  title_2010 = c("Entertainment and Recreation Managers, Except Gambling", "Industrial Production Managers", "Sales Managers", "Logisticians", "Accountants and Auditors"),
  code2010 = c("11-9072", "11-3051", "11-2022","13-1081","13-2011")  
)

# Print the data frame
Data_Frame

DF1 <- data.frame(title_2000 = c(" All Other Managers", "Logistics Engineers"),
code_2000 = c("11-9199", "13-1081"),
title_2010 = c("Entertainment and Recreation Managers, Except Gambling",  "Logisticians"),
  code2010 = c("11-9072", "13-1081")  
)

DF1

DF2<- data.frame (
  title_2000 = c( "Industrial Production Managers", "Sales Managers",  "Accountants and Auditors"),
  code_2000 = c( "11-3051", "11-2022", "13-2011"),
  title_2010 = c( "Industrial Production Managers", "Sales Managers",  "Accountants and Auditors"),
  code2010 = c( "11-3051", "11-2022","13-2011")  
)

DF2

Is this what you are looking for?

Data_Frame <- data.frame (
  title_2000 = c(" All Other Managers", "Industrial Production Managers", "Sales Managers", "Logistics Engineers", "Accountants and Auditors"),
  code_2000 = c("11-9199", "11-3051", "11-2022", "13-1081", "13-2011"),
  title_2010 = c("Entertainment and Recreation Managers, Except Gambling", "Industrial Production Managers", "Sales Managers", "Logisticians", "Accountants and Auditors"),
  code2010 = c("11-9072", "11-3051", "11-2022","13-1081","13-2011")  
)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
DF1 <- Data_Frame |> filter(title_2000 != title_2010 | code_2000 != code2010)
DF1
#>            title_2000 code_2000
#> 1  All Other Managers   11-9199
#> 2 Logistics Engineers   13-1081
#>                                               title_2010 code2010
#> 1 Entertainment and Recreation Managers, Except Gambling  11-9072
#> 2                                           Logisticians  13-1081

DF2 <- Data_Frame |> filter(title_2000 == title_2010 & code_2000 == code2010)
DF2
#>                       title_2000 code_2000                     title_2010
#> 1 Industrial Production Managers   11-3051 Industrial Production Managers
#> 2                 Sales Managers   11-2022                 Sales Managers
#> 3       Accountants and Auditors   13-2011       Accountants and Auditors
#>   code2010
#> 1  11-3051
#> 2  11-2022
#> 3  13-2011

Created on 2022-08-25 by the reprex package (v2.0.1)

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.