dataframe - Is there an R dplyr method for merge with all=TRUE? -
I have two R dataframes that I want to merge. You can do this directly in R:
Cost & lt; - data.frame (farm = c ('form a', 'office'), cost = c (10, 100)) trees and lts; - data.frame (farm = c ('form a', 'form b'), tree = c (20,30) merge (cost, tree, all = true) Which produces:
Agricultural Costs Tree 1 Farm A10202 Office 100 NA3 Form BNA 30 I dplyr < / Code>, and prefer a solution such as:
left_join (cost, tree) which makes me close to something I want: left_join
agricultural cost tree 1 form A10202 office 100a in dplyr Code>, internal_j In , semi_joined and anti-joints , but none of which is merge with all = TRUE does.
In addition - is there a quick way to set NAs to 0? My efforts are still using x $ tree [is.na (x $ tree)] <0, laborious (I need a per-pillar command) and do not always seem to work Happen.
Thanks
Latest version of dplyr 0.4.0 ) Now there is a full_joined option, which is what I believe you want.
Costs & lt; - data.frame (farm = c ('form a', 'office'), cost = c (10, 100)) tree < - data.frame (farm = c ('form a', 'form b'), tree = c (20,30) merge (cost, tree, all = true) Return
& gt; Merge (cost, tree, all = TRUE) Farming cost 1 Farm A10 20 2 Office 100 NA 3 Form BNA 30Library (Dplyr) Full_Joy (cost, tree) < / Code>returns
& gt; Full cost (cost, tree): "farm" farm cost tree 1 farm A10202 office 100 NA3 form BNA 30 warning message: joining factors with different levels, coastering character vector
Comments
Post a Comment