0

dataframe tidy2: enter image description here

I'd like to convert the part of dataframe that satisfies my specific conditions into a list. For example, for all communities contain "BAYSHIRE", I want to store their facility number, name and licensee as the first element in a list and called this element "BAYSHIRE", for communities contain "EMERITUS" or "BROOKDALE", store their facility number name and licensee as the second element in a list.

key = list("BAYSHIRE", c("EMERITUS", "BROOKDALE"), "AGEMARK")
big_organization <- list()

for (i in 1:length(key)){
  org = tidy2 %>%
    filter(str_detect(Licensee, key[[i]]) | str_detect(Facility_name, key[[i]] )) %>%
    select(Facility_number, Facility_name, Licensee)

     
  big_organization = append(big_organization, or)
}
big_organization

Output for above code: enter image description here

ck.imgur.com/88Ya3.png

Expected output:

$BAYSHIRE

Facility_number Facility_name Licensee

374604274 VISTA DEL LAGO MEMORY CARE DEL DIOS CARE,LLC;BAYSHIRE, LLC
374604267 CLOISTERS OF THE VALLEY, LLC DEL RIO CARE, LLC; BAYSHIRE, LLC
374603778 HERITAGE HILLS HAWKES O-SIDE 1 LLC; BAYSHIRE LLC

$EMERITUS, BROOKDALE

Facility_number Facility_name Licensee

336413087 BROOKDALE MURRIETA BLC CHANCELLOR-MURRIETA LH LLC
197606301 BROOKDALE MONROVIA BLC GABLES-MONROVIA LP
197606676 BROOKDALE GARDENS OF TARZANA BLC GARDENS-TARZANA, LP
496803339 BROOKDALE PAULIN CREEK BLC LODGE AT PAULIN INC GP, BLC LODGE AT PAULIN LP
306002955 BROOKDALE NOHL RANCH BLC NOHL RANCH LLC
198204758 BROOKDALE OCEAN HOUSE BLC OCEAN HOUSE LP
374601046 BROOKDALE PLACE OF SAN MARCOS BLC-BROOKDALE PLACE OF SAN MARCOS LP
306003639 BROOKDALE BREA BREA BREA LLC; EMERITUS CORPORATION
347003712 BROOKDALE SYLVAN RANCH BREA CITRUS HEIGHTS LLC; EMERITUS CORPORATION
197606945 BROOKDALE CENTRAL WHITTIER BREA WHITTIER LLC; EMERITUS CORPORATION . . . .

Markus Meyer
  • 3,327
  • 10
  • 22
  • 35
Phyllis
  • 1
  • 2
  • What is your expected output? – Himanshu Poddar Jul 12 '22 at 05:50
  • It would be easier for us to help you with an actual sample of your data. Please see [how to make great r reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Anyway, you can have a look to `purrr::map`. Here's an example with `iris` dataset: `output <- map(levels(iris$Species), function(x){ iris |> filter(str_detect(Species,x)) } ) names(output) <- levels(iris$Species)` – MonJeanJean Jul 12 '22 at 05:55

0 Answers0