如何最好地将这两个数据框加在一起?

问题描述 投票:0回答:0

以下是示例数据。这是我想做的..我有数据 在第一个数据框中。这是一个调整。第二个数据框是现有数据。对于 d2022 这一年,我需要从第二个项目中减去第一个的值。我该怎么做?

这是调整

 indcode  <- c(482000,482000,482000,524000,524000,524000)
 area <- c(000032,029820,039900,000032,029820,039900)
 ownership <- c(50,50,50,50,50,50)
 d2022 <- c(10,6,2,100,60,20)

 First<-data.frame(indcode,area,ownership,d2022)

 ## This is the existing data

 indcode <- c(482000,482000,482000,484000,484000,484000,524000,524000,524000,531000,531000,531000)
 area <- c(000032,029820,039900,000032,029820,039900,000032,029820,039900,000032,029820,039900)
 ownership <- c(50,50,50,20,30,50,50,50,50,20,30,50)
 d2020 <- c(200,199,198,197,196,195,194,193,192,191,190,189)
 d2021 <- c(201,200,199,198,197,196,195,194,193,192,191,190)
 d2022 <- c(204,203,202,201,200,199,198,197,196,195,194,193)

 second <- data.frame(indcode1,area1,ownership1,d2020,d2021,d2022)
r join dplyr bind
© www.soinside.com 2019 - 2024. All rights reserved.