I am relatively inexperience in r and am trying to do work that's relatively simple, but get repeated similar errors. For example, I am working with a dataset and trying to generate a simple crosstabulation of two variables using crosstable in an attached dataset. The dataset was imported from an SPSS .sav file.
crosstable(battle04, region)
Error in crosstable(battle04, region) : 1 assertions failed:
- Variable 'data': Must be of type 'data.frame', not
- 'haven_labelled/vctrs_vctr/double'.
crosstable(abortlaw, region)
Error in crosstable(abortlaw, region) : 1 assertions failed:
- Variable 'data': Must be of type 'data.frame', not 'double'.
This is not the first time I've had an error message along these lines and am perplexed what the problem is.
crosstable()needs as the first argument the dataset, and as the second argument a vector of columns to describe.For instance, if I want to describe the columns
Sepal.LengthandSpeciesfrom the datasetiris2, you should write this:Created on 2022-11-10 with reprex v2.0.2
In your case, the error message says that in your code
crosstable(battle04, region),battle04should be a dataset (of classdata.frame) but it is a vector of classhaven_labelled/vctrs_vctr/double.As @stefan said in the comments, we will need a sample of your dataset to help you with some code.