I have a data frame of live trapping. There are two systems, each with different status. The week and the number of individuals in each status is given.
df <- data.frame (sys = rep(c("a","b"), each=3),
sta = rep(c("L","T","P"), times=2),
w01 = c("0","2","5","2","2","5"),
w02 = c("3","2","2","4","6","1"),
w03 = c("4","1","0","5","3","0"))
df
sys sta w01 w02 w03
a L 0 3 4
a T 2 2 1
a P 5 2 0
b L 2 4 5
b T 2 6 3
b P 5 1 0
I want a data frame showing for each number the system and status. The Result would look like this:
sys sta Num
a L 0
a L 3
a L 4
a T 2
a T 2
a T 1
a P 5
a P 2
a P 0
b L 2
b L 4
b L 5
b T 2
b T 6
b T 3
b P 5
b P 1
b P 0
I have absolutely no idea how doing this. I found this two questions/answers
Reorganise 2x36 dataframe to a 6x6 dataframe. Dice throw visualisation
Reshaping data.frame from wide to long format
but cannot find a way to fit it for my problem.
Also i tried reshape
but direction = "wide"
does not give the output I need and I am sucked with the varying part of direction = "long"
. Here is what I tried, but did not work...
a <- as.vector(colnames(df[-c(1,2)]))
df2 <- reshape(df, idvar = "sys", timevar = "sta", varying = a , direction = "long")
Any suggestions how I can solve this problem? Thank you all and kind regards!
P.S.: I need the "new format" of my dataset for a friedman test (friedman.test
). Will it work out in this way?