0

I am working with the following dataframe called example :

structure(list(person = c(1, 2, 3), animal = c(4, 5, 6), type = c("a", "b", "c")), class = "data.frame", row.names = c(NA, -3L))

I am looking for a way to create a new dataframe containing a new column, "value", that joins the numeric values of "person" and "animal" as rows, and would replicate the corresponding character value in "type".

The structure of this second dataframe would like the following in example2:

structure(list(value = c(1, 2, 3, 4, 5, 6), being = c("person", "person", "person", "animal", "animal", "animal"), type = c("a", "b", "c", "a", "b", "c")), class = "data.frame", row.names = c(NA, -6L))

How could I achieve this using functions?

(The idea would be to use this method for a much larger dataframe)

All the best,

Cameron

Cameron
  • 85
  • 6

0 Answers0