I'm a little confused by the reproducible example provided. What is throwing the error 'data' must be 2-dimensional (e.g. data frame or matrix)
?
This seems to reveal that this is in fact a list, not a data.frame.
If you're still having issues, could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.