Hi R users,
I was trying to create a pivot table (cross tabulated) by Site1date (rows)
and Site2 date (columns), and spent substantial time but no luck to create
it. Is there any possibility to create it?
I would be very grateful to your help.
"daT1" is row data, in which three columns (speciesID, detected at SiteA,
Site B) and cell has date in which they were detected. From this data, I
wanted to create a table to show a joint detection between site1 and Site2.
I was trying to get the table similar to "daT2", which is a cross tabulated
table by Site1 date (rows), and Site2 date (columns). After that I would
like to see another table related sum of the detecttions in each cell (
The example data are given below (daT1) and output tables (daT2, daT3). I
appreciate your help very much.
Thank you very much for the code. It is great as it gave the number of
individuals encountered in each cell but- is it possible to see which
individuals were in that cell?
for example - site2 (2015-05-02) and site2(2015-03-31) has value 2, is it
possible to show these two "941FD","8737SP" IDs in that cell? It must be
hard to create this type of table.
sapply(daT1, class) ## factors interfere with what you want.
## make ID "character" and the two date columns "Date"
daT2 <- data.frame(ID=as.character(daT1$ID),
site1=as.Date(daT1$site1, format = "%d-%b-%Y"),
site2=as.Date(daT1$site2, format = "%d-%b-%Y"),
result <- tapply(daT2$ID, daT2[,2:3], c)