First, I apologize for clunky formatting...I do not program, just trying to learn r and run some analyses...
I am running dcast to reshape a dataset from long to wide. This code was used previously without issues, but now about 6 months later it will not work correctly.
Example of dataset structure
- id m v1 v2 v3
- A 1 f 1 p
- A 2 e 2 o
- A 3 k 3 j
- A 4 l 1 o
- B 1 k 2 p
- B 2 d 3 o
- B 3 a 1 j
- B 4 l 6 o
...
There are 4218 unique IDs and each has one occurrence of each m. I have verified the count of m matches the unique id and that among the vector of id*m there are no duplicates.
I am trying to get a wide dataset:
id m m1v1 m1v2 m1v3 m2v1 m2v2 m2v3
My code is as follows:
y <- dcast(setDT(mydata), 'id' ~ 'm', value.var = c('v1', 'v2', 'v3')
This ran without error about 6 months ago, but reloading in new data with the same structure but different variable names has resulted in the error:
"Aggregate function missing, defaulting to 'length'"
There are no duplicates (verified all rows unique with respect to id and m), so I cannot figure out why this is happening. All other answers regarding this issue are due to duplicate values.