I'm trying to convert from wide to long data, but having trouble with a specific problem. Each person has a row of rooms in a hotel, but I only know their first and last room. I'd like to fill in the rooms that are between first and last room.
data = read.table(text="
name first_room last_room
A 2 5
B 4 7", header=TRUE)
and I'm trying to get every room each person has, including the ones in between.
I've tried using gather in tidyr, but that only gives me the first and last room.
data %>% gather(type, room, -1) %>% arrange(name)
current output:
name type room
1 A first_room 2
2 A last_room 5
3 B first_room 4
4 B last_room 7
wanted output:
Name type room
1 A first_room 2
2 A last_room 3
3 A last_room 4
4 A last_room 5
5 B first_room 4
6 B first_room 5
7 B first_room 6
8 B first_room 7