I would like to convert a dataframe containing zip codes and relationships between zip codes into a list.
I looked at ways to convert dataframes into lists as well as the spread function.
The first column (codes1) contains all zip codes of a zone. The second column (codes2) contains the zip codes of the cities related to the first one.
df<-as.data.frame(cbind(rep(1:4, c(2,5,4,3)),c(2,4,4,3,6,8,7,1,2,8,7,1,2,3)))
colnames(df)<-c("codes1","codes2")
df
I would like to obtain a list like this one, containing for each zip code the related zip codes:
l <- list(c(2,4), c(4,3,6,8,7),c(1,2,8,7),c(1,2,3))
l