I am struggling in transforming the data to long format
In R, I have the following data:
alcolevel <- c(0,0.5,1.5,4.0,7.0)
present <- c(48,38,5,1,0)
absent <- c(17066,14464,788,126,37)
dataset1 <- data.frame(alcolevel,present,absent)
alcolevel present absent
1 0 48 17066
2 0.5 38 14464
3 1.5 5 788
4 4.0 1 126
5 7.0 0 37
I wish to transform dataset1 into this:
alcolevel Y
0 present
0 present
0 absent
0 absent
0 absent
. .
. .
. .
0.5 absent
0.5 present
0.5 present
0.5 present
. .
. .
. .
1.5 present
. .
. .
. .
7.0 present
7.0 present
so I get 48 present and 17066 absent for alcolevel 0
. Same for other alcolevel
categories.
After the transformation, the new long dataset is gonna be a long one.
I appreciate any help with this problem. Thanks