Hi everyone,
I have a problem with my coordinates data. I want to make a kernel analysis, but my coordinates data are read as characters. I've tried to use several packages but it always leads to error. Any suggestion for this? Here is my script.
kernel1 <- kerneldata[, c("id", "lon", "lat")]
#make kernel1 data with only id, lon, and lat
View(kernel1)
kernel2 <- na.omit(kernel1)
View(kernel2)
kernel1 <- kerneldata[, c("lon", "lat")]
View(kernel1)
kernel2 <- na.omit(kernel1)
View(kernel2)
kernel3 <- as.numeric(kernel2)
Error: 'list' object cannot be coerced to type 'double'
kernel3 <- as.numeric(unlist(kernel2))
Warning message:
NAs introduced by coercion
summary(kernel2)
lon lat
Length:10543 Length:10543
Class :character Class :character
Mode :character Mode :character
clean <- raw %>%
st_as_sf(wkt = "geometry",
crs = 4326)
Error in UseMethod("st_as_sf") :
no applicable method for 'st_as_sf' applied to an object of class "function"
clean <- raw %>%
st_as_sf(wkt = "geometry",
crs = 4326)
Error in UseMethod("st_as_sf") :
no applicable method for 'st_as_sf' applied to an object of class "function"
class(data$lon)
Error in data$lon : object of type 'closure' is not subsettable
class(data$"lon")
Error in data$lon : object of type 'closure' is not subsettable
View(kernel2)
class(data$lat)
Error in data$lat : object of type 'closure' is not subsettable
could you post a small subset of the data - it would be easier to help you that way and you will probably get a proper response of why this behaviour occurs.
As you can see, my coordinates become characters data. When I tried to change it into numeric, the data becomes NA.
trial1$lon <- as.numeric(trial1$lon)
Warning message:
NAs introduced by coercion
trial2
id lon lat
1 fe_pre NA -7,278500972
2 lp_pre NA -7,28
3 hs_pre NA -7,28
4 lu_post_l NA -7,28
5 lu_post_l NA -7,28
6 lu_post_l NA -7,28
7 lu_post_l NA -7,28
8 lu_post_l NA -7,28
9 lu_post_l NA -7,28
10 lu_post_l NA -7,28
11 lu_post_l NA -7,28
12 lu_post_l NA -7,28
13 lu_post_l NA -7,28
14 lu_post_l NA -7,28
the dput() function gives use an exact copy of the dataset so we can see how your data in organized, it a variable is numeric or a factor, etc. It makes diagnosing a problem much easier. Heru `kerneldata' seems to be iun a list or lists format.
It your case I think we want dput(kerneldata) where "mydata" is the name of your dataset. If it is large datasets probably dput(head(kerneldata, 100)) will do. Paste the output between
```
```
Also, it is a good idea to post code between
```
```
as it gives us better formatted code.
You are using the function st_as_sf(). What package is that from?
is that it will make it work for your ";" separated file (you are probably working in germany or austria so they don't use "," for separation but ; and "," instead of "."for decimal separation). The read.csv function assumes that decimal places are sperated by "." yours are separated by ",". Also R seeing "," will convert to character instead of numeric since it thinks that "," can't be properly converted to numerics.
Thank you so much! It works!
I'm still new in R (even in this community) and this answer helps a lot!
Yes, mine was reading "," as decimal separations.
Have a good day and may God blessed you !