Can you create a table with categories and what is classified under each one from a data frame

is there a way to change a table like this A to B:

TABLE A - made up data

CAT Type
home house
holiday caravan
holiday hotel
home bungalow

TABLE B - change to:

Home Holiday
House caravan
bungalow hotel

I am new to r and have tried pivots and list but not sure if I am doing it right.


  • You can try

    > with(df, list2DF(split(Type, CAT)))
      holiday     home
    1 caravan    house
    2   hotel bungalow


    df <- structure(list(CAT = c("home", "holiday", "holiday", "home"),
        Type = c("house", "caravan", "hotel", "bungalow")), class = "data.frame", row.names = c(NA,