0

I want to fill columns of first dataframe wherein column 'Link' is missing from second dataframe. In short MISSING values of columns 'Link' and 'Status' to be filled from second dataframe. Since 'Sector' and 'Industry' columns are already filled in first dataframe against missing values of link, they should remain as it is. Joining key is 'Company'. Would prefer dplyr or base R solution.

First Dataframe

temp <- structure(list(Company = c("NGL Fine Chem", "EKI Energy Services", 
    "Gtn Textiles", "Z.F. Steering Gear (India)", "Larsen & Toubro Infotech", 
    "Thomas Cook India Fully Paid Ord. Shrs", "GNA Axles", "Marathon Nextgen Realty", 
    "Rajnandini Metal", "Dynemic Products.", "POONAWALLA FINCORP", 
    "ADF Foods.", "Max India Ord Shs", "Shiva Mills Ord Shs", "Diksat Transworld", 
    "Winsome Textile Industries", "Strides Pharma Science", "Kakatiya Cement Sugar And Industries", 
    "D Link India", "TGV SRAAC", "Kaira Can Co.,", "Mohota Industries", 
    "SEACOAST SHIPPING SERVICES", "Mahindra Holidays & Resorts India.", 
    "TechNVision Ventures", "Coal India"), Link = c(NA, NA, "GTNTEX/gtn-textiles-ltd/", 
    NA, "LTI/larsen-toubro-infotech-ltd/", "THOMASCOOK/thomas-cook-india-ltd/", 
    "GNA/gna-axles-ltd/", "MARATHON/marathon-nextgen-realty-ltd/", 
    "RAJMET/rajnandini-metal-ltd/", "DYNPRO/dynemic-products-ltd/", 
    NA, "ADFFOODS/adf-foods-ltd/", "MAXIND/max-india-ltd/", "SHIVAMILLS/shiva-mills-ltd/", 
    NA, NA, "STAR/strides-pharma-science-ltd/", "KAKATCEM/kakatiya-cement-sugar-industries-ltd/", 
    "DLINKINDIA/d-link-india-ltd/", NA, NA, "MOHOTAIND/mohota-industries-ltd/", 
    NA, "MHRIL/mahindra-holidays-resorts-india-ltd/", NA, "COALINDIA/coal-india-ltd/"
    ), Sector = c("Healthcare", "Industrials", NA, "CDGS (Consumer Discretionary Goods & Services)", 
    "Information Technology", "CDGS (Consumer Discretionary Goods & Services)", 
    "CDGS (Consumer Discretionary Goods & Services)", "CDGS (Consumer Discretionary Goods & Services)", 
    NA, "Basic Materials", "Finance", "FMCG (Fast Moving Consumer Goods)", 
    NA, "CDGS (Consumer Discretionary Goods & Services)", "CDGS (Consumer Discretionary Goods & Services)", 
    "CDGS (Consumer Discretionary Goods & Services)", "Healthcare", 
    "Basic Materials", "Information Technology", "Basic Materials", 
    "Industrials", NA, "Industrials", "CDGS (Consumer Discretionary Goods & Services)", 
    "Information Technology", "Energy"), Industry = c("Pharmaceuticals & Biotechnology", 
    "Commercial Services & Supplies", NA, "Automobiles & Auto Components", 
    "Software & Services", "Hotels, Restaurants & Tourism", "Automobiles & Auto Components", 
    "Realty", NA, "Chemicals & Petrochemicals", "Other Financial Services", 
    "Food, Beverages & Tobacco", NA, "Textiles, Apparels & Accessories", 
    "Media", "Textiles, Apparels & Accessories", "Pharmaceuticals & Biotechnology", 
    "Construction Materials", "Hardware Technology & Equipment", 
    "Chemicals & Petrochemicals", "General Industrials", NA, "Transportation", 
    "Hotels, Restaurants & Tourism", "Software & Services", "Coal"
    ), Status = c(NA, NA, "AA", NA, "BB", "BB", 
    "BB", "BB", "Strongly AA", "BB", 
    NA, "BB", "BB", "BB", NA, NA, "BB", 
    "AA", "BB", NA, NA, "BB", NA, "BB", 
    NA, "AA")), row.names = c(NA, -26L), class = c("tbl_df", 
    "tbl", "data.frame"))

Second Dataframe

   temp2 <- structure(list(Company = c("TGV SRAAC", "POONAWALLA FINCORP", 
"EKI Energy Services", "NGL Fine Chem", "SEACOAST SHIPPING SERVICES", 
"TGV SRAAC", "Z.F. Steering Gear (India)", "Kaira Can Co.,", 
"Diksat Transworld", "Winsome Textile Industries", "TechNVision Ventures"
), Link = c("SREERAYALK/tgv-sraac-ltd/", "POONAWALLA/poonawalla-fincorp-ltd/", 
"eki-energy-services-ltd/", "NGLFINE/ngl-fine-chem-ltd/", "seacoast-shipping-services-ltd/", 
"SREERAYALK/tgv-sraac-ltd/", "ZFSTEERING/zf-steering-gear-india-ltd/", 
"KAIRA/kaira-can-company-ltd/", "DIKSAT/diksat-transworld-ltd/", 
"WINSOMTX/winsome-textile-industries-ltd/", "TECHNVISN/technvision-ventures-ltd/"
), Sector = c(NA_character_, NA_character_, NA_character_, NA_character_, 
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, 
NA_character_, NA_character_), Industry = c(NA_character_, NA_character_, 
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, 
NA_character_, NA_character_, NA_character_, NA_character_), 
    Status = c("BB", "AA", "AA", 
    "BB", "BB", "strongly AA", 
    "AA", "BB", "BB", 
    "AA", "BB")), row.names = c(NA, 
-11L), class = c("tbl_df", "tbl", "data.frame"))
Ujjawal Bhandari
  • 1,231
  • 1
  • 8
  • 14

0 Answers0