Fairly novice R user, and I'm sure there's an easy solution for this - but I can't find it. I have a data frame with a series of spatial coordinates, as well as a host of other attributes. Many of the spatial coordinates are the exact same - and I would like to add a set amount of noise to them, so that I can keep them within a certain radius - in this case 0.4 meters, or 40 centimeters while also keeping track of their associated attributes.
I am essentially looking for an R version of this question: https://gis.stackexchange.com/questions/35479/adding-noise-to-overlapping-x-y-coordinates-so-no-longer-in-exact-same-place
... because when I follow the directions for the answer to this question using ArcGIS - I get a series of random points but I lose the attributes associated with those points, and I can't easily find a way to match them back up.
Is there a way to use the jitter function in R or something similar and specify the radius in a spatial context (e.g. 40 cm) that the spatial coordinates are randomly distributed within that range? I don't understand how to manipulate the factor and amount argument in order to get my desired output.
Edit:
Here's an example df with fake coordinates. As you can see the coordinates in the first and third column are the same, because the animal was under the same rock twice. I would like to be able to add jitter to these coordinates so they are slightly different, but I want to control the jitter to be within 40 centimeters (no more than the size of the rock)
mydf <- data.frame("point_id" = 1:6, "date_time" = c("6/5/2018 10:57","6/5/2018 14:30","6/6/2018 10:06","6/6/2018 11:06","6/7/2018 10:35","6/7/2018 15:50"), "Animal_ID" = c(4,5,4,5,4,6), "Rock_ID" = c(1,2,1,3,4,5), x_proj = c(831120.3759,831441.0415,831120.3759,831433.4414,831128.4778,831422.0822), y_proj = c(5877582.998,5875337.074,5877582.998,5875328.897,5877575.360,5875338.216))
#make a separate object for the coordinates#
xy <- mydf[,c(5,6)]
#Convert to a spatialpoints data frame (insert own epsg)
sp.mydf <- SpatialPointsDataFrame(coords = xy, data = tumbling_test, proj4string = CRS("+init=epsg:xxxxx"))
I want my newly generated coordinates to still contain the attribute data from other columns (i.e. Animal_ID, date, etc) because other methods I have used in ArcGIS generate a series of new random pts but I can't match them back to the attributes.
Also if there is a way to only add the jitter to points that have more than one occurrence at a rock, that would be neat. For example here I only need to add the jitter to rows 1 and 3, because the other coordinates do not repeat. Once the jitter is added, I want to convert the results back to a regular dataframe that I will export to a .csv