0

I am trying to build a web scraper that'll go through a number of websites and extract some information. In order to do this, I'm going to need to make a list of the last couple of characters in the url, so I can map the information into a data frame. To do this, I've found out that the end of the url should have a number between 1 and 10 to identify a department, and a given character to identify a unit. Therefore I've made two vectors with the needed units and department IDs:

departments <- c(1, 2, 9, 10)
units <- c("A", "B", "C", "F", "I", "O", "V")

To go through each website, I need a list that combines these two vectors in each possible way, like for instance "1A", "1B", "1C", "1F", "1I", "1O", "1V", "2A" and so forth.

I've tried different solutions, but they do not return what I expected, like for instance:
> depUn <- as.list(paste(departments, units, sep = ""))
> depUn
[[1]]
[1] "1A"

[[2]]
[1] "2B"

[[3]]
[1] "9C"

[[4]]
[1] "10F"

[[5]]
[1] "1I"

[[6]]
[1] "2O"

[[7]]
[1] "9V"

Does someone have any good insight to how I could solve this?

EDIT I've already tried the expand.grid option, and while it was succesful in putting the elements after one another in a list, it failed to put them together in one string. Can someone help me how to accomplish this? Here's and excerpt of the code and results I tried back then:

> dfDepUn <- expand.grid(departments, units)
> DepUn <- lapply(apply(dfDepUn, 1, identity), unlist)
> dfDepUn
[[1]]
Var1 Var2 
 "1"  "A" 

[[2]]
Var1 Var2 
 "2"  "A" 

[[3]]
Var1 Var2 
 "9"  "A" 

[[4]]
Var1 Var2 
"10"  "A"  
Nordsted
  • 97
  • 2
  • 12

1 Answers1

0

Is this what you need?

df <- expand.grid(departments, units)
as.list(paste0(df$Var1, df$Var2))
nael_kl
  • 89
  • 3
  • Thanks, but I tried that already, as I just edited in my original question. But Henrik provided the answer I needed in the comments – Nordsted May 27 '18 at 12:28