0

My data looks like this:

year country
1990 USA
1991 USA
1991 UK
1990 UK
1991 USA
1991 UK
1992 USA
1992 UK
1992 UK

I am trying to execute the following row of the code

Freq <- data.frame(with(data_frame, table(year, country)))

to get the frequencies of each country in my data set in every year that looks like this.

year country frequency
1990 USA 1
1991 USA 2
1992 USA 1
1990 UK 1
1991 UK 2
1992 UK 2

Until recently, the code worked okay and this is exactly what I had as an output. Today I installed an RSelenium package and after that by executing the row above I get the error

Error in unique.default(x, nmax = nmax) : unique() applies only to vectors

I don't know if Selenium has something to do with it. Why can this happen, and how can I fix this? Any tips will be very appreciated.

I already read this question, but unfortunately, it was of no use for me.

P.S.: this is my first question here, sorry, if it's a little crooked.

  • Can you please make your data reproducible? See tips on how here: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example. PS. With the data provided in akrun answer your code works fine. – s_baldur Jun 18 '21 at 13:10

1 Answers1

0

An option with count

library(dplyr)
count(df1, year, country)

-output

year country n
1 1990      UK 1
2 1990     USA 1
3 1991      UK 2
4 1991     USA 2
5 1992      UK 2
6 1992     USA 1

data

df1 <- structure(list(year = c(1990L, 1991L, 1991L, 1990L, 1991L, 1991L, 
1992L, 1992L, 1992L), country = c("USA", "USA", "UK", "UK", "USA", 
"UK", "USA", "UK", "UK")), class = "data.frame", row.names = c(NA, 
-9L))
akrun
  • 874,273
  • 37
  • 540
  • 662