It has been a while since I've used R, so apologies for this very simple question. I probably wouldn't be asking it if I knew the correct way to find the question with the right keywords on a search engine.
I have a really long data table with a few columns, two of which are the subject for this question. The data table looks something like:
Row|Q|Year
1 |1|1990
2 |3|1995
3 |3|1991
4 |2|1990
5 |1|1990
6 |1|1990
7 |1|1992
8 |2|1991
9 |1|1990
10 |1|1990
11 |4|1991
12 |1|1992
13 |2|1995
14 |1|1993
15 |1|1990
....etc
I want to make a table that counts all the the Year records for a given Q like below
Q|1990|1991|1992|1993|1994|1995
1|5 |2 |2 |1 |3 |2
2|6 |6 |2 |1 |4 |1
3|2 |1 |4 |5 |6 |1
4|4 |3 |1 |2 |7 |6
...etc.
Or a way to extract that information one by by one Q=1, Year=1990: 5
I don't want to do it with a fancy package or with for/while loops, if I remember correctly it should just be something really simple with the basic R package like
table(data$Q,data$Year)
or
count(data$Q[Q==1,], data$Year[Year==1990,])
Though obviously that doesn't work because the length of X is different than the length of Y
Again sorry, a really dumb basic R question
table(data$Q,data$Year)
work for you? That should do what you want....
since we can't reproduce that.as.data.frame.matrix(table(data$Q, data$Year))
and then usewrite.csv()
like any other data.frame in R.