Concept Flow - List to vector conversion
Start with a list
Check list elements
Flatten elements into a single vector
Return the vector
This flow shows how R takes a list and combines its elements into one vector.
my_list <- list(1, 2, 3) my_vector <- unlist(my_list) print(my_vector)
| Step | Action | Input | Output | Notes |
|---|---|---|---|---|
| 1 | Create list | list(1, 2, 3) | my_list <- list(1, 2, 3) | List with 3 elements created |
| 2 | Call unlist() | my_list | c(1, 2, 3) | List flattened into vector |
| 3 | Print vector | c(1, 2, 3) | 1 2 3 | Vector printed to console |
| 4 | End | - | - | Conversion complete |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| my_list | NULL | list(1, 2, 3) | list(1, 2, 3) | list(1, 2, 3) |
| my_vector | NULL | NULL | c(1, 2, 3) | c(1, 2, 3) |
List to vector conversion in R: - Use unlist() to flatten a list - unlist() combines all elements into one vector - Elements coerced to common type if needed - Result is a simple vector, easy to use in calculations