Arguments implying differing number of rows:47, 50, 56

Is there a simple way to assign a blank to the rows that are missing data? I appreciate the help in advance, thanks!

library(rvest)
library(dplyr)

bbs <- html("https://www.bizbuysell.com/california-businesses-for-sale/?q=aXI9MSZzcGlkPTEmdz1x")

bbs.price <- bbs %>%
html_nodes(".price") %>%
html_text()

bbs.location <- bbs %>%
html_nodes(".info") %>%
html_text()

bbs.cashflow <- bbs %>%
html_nodes(".hidden-phone") %>%
html_text()

bbs.df <- data.frame(price=bbs.price, location=bbs.location, cashflow=bbs.cashflow)
dim(bbs.df)

This was interesting because I learned that constructing a tibble/data.frame with a variable that you assign only a character(0) to, means the whole row will not be created, so thats why I paste and empty string.

library(rvest)
library(dplyr)

bbs <- html("https://www.bizbuysell.com/california-businesses-for-sale/?q=aXI9MSZzcGlkPTEmdz1x ")


bbs_listingresults<- bbs %>% html_nodes(".listingResult")

library(purrr)
map_dfr(bbs_listingresults,

     ~ tibble(price=paste0("",html_text(html_nodes(.,".price"))),
                  info=paste0("",html_text(html_nodes(.,".info"))),
                  hiddenphone=paste0("",html_text(html_nodes(.,".hidden-phone")),collapse = ";"))
                  
) -> bbs_listingresults_df

bbs_listingresults_df
# A tibble: 50 x 3
   price        info                   hiddenphone                         
   <chr>        <chr>                  <chr>                               
 1 "$250,000"   Los Angeles, CA        Cash Flow: $60,000;Contact Seller   
 2 "$324,000"   Sacramento, CA         Cash Flow: $108,000;Contact Seller  
 3 "$1,650,000" Modesto, CA            Cash Flow: $519,388;Contact Seller  
 4 "$780,000"   Los Angeles County, CA Cash Flow: $192,165;Contact Seller  
 5 "$2,000,000" Los Angeles County, CA Cash Flow: $436,216;Contact Seller  
 6 "$249,000"   Pasadena, CA           Cash Flow: $135,000;Contact Seller  
 7 "$730,000"   Los Angeles County, CA Cash Flow: $368,381;Contact Seller  
 8 "$260,000"   Orange, CA             Contact Seller                      
 9 "$42,768"    San Diego, CA          Cash Flow: $41,805;Contact Seller   
10 ""           Orange County, CA      Cash Flow: $1,538,900;Contact Seller
# ... with 40 more rows
1 Like

This was super helpful, thank you!

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