r - hierarchical data frame from child/parent relations
问题 I have a child - parent data.frame that I want to transform to a complete hierarchical list with all levels and a level number. The example data below goes to three levels, but it could be more. What function can I use to transform the data? Source: data.frame(name = c("land", "water", "air", "car", "bicycle", "boat", "balloon", "airplane", "helicopter", "Ford", "BMW", "Airbus"), parent = c(NA, NA, NA, "land", "land", "water", "air", "air", "air", "car", "car", "airplane")) name parent 1 land