I have a large data frame (100,000 rows) with LON, LAT, VALUE which i want to convert into a matrix. (coordinates in EPSG:3035).
I tried the reshape2 package with the following command
acast(df, lon~lat, value.var="value")
which worked wonderfully.
When i transformed the coordinates to 'EPSG:4326' and run the same code, its when i get the error.
str(df1)
data.frame': 168643 obs. of 3 variables:
$ x: num 28 28.1 27.8 28 28.1 ...
$ y: num 71.1 71 71 71 71 ...
$ z: num 0.0893 0.093 0.085 0.0886 0.0924 ...
> aa=acast(df1, x~y, value.var="z")
Error in seq_len(n) : argument must be coercible to non-negative integer
In addition: Warning message:
In match(seq_len(n), overall, nomatch = NA) : NAs introduced by coercion
For a reproducible example like the one given below, the code works, but why is it for large data frame like i have, i am getting the error. Has it got to do anything with the transformation of the coordinates.
x=c(-8.084929925, -8.01229693, -7.939629855, -7.866928803, -7.794193877, -7.721425179, -7.648622813, -7.575786885, -7.502917498, -7.430014757, -7.357078769, -7.284109638, -7.211107472, -7.138072377, -7.065004461, -6.99190383)
y=c(53.07977473, 53.09085897, 53.10189964, 53.11289671, 53.12385014, 53.1347599, 53.14562596, 53.15644829, 53.16722685, 53.17796162, 53.18865255, 53.19929962, 53.2099028, 53.22046205, 53.23097734, 53.24144865)
z=c(0.065, 0.063, 0.062, 0, 0, 0, 0.061, 0.062, 0.064, 0.06, 0.069, 0.074, 0.079, 0.08, 0.092, 0.10)
df=data.frame(x,y,z)
acast(df, x~y, value.var="z")
Any thoughts?