I have three lists – lat, long, wifiRssi. Each list has the same number of rows. lat and long will always have the same number of elements per row. wifiRssi will usually have less elements than lat/long but sometimes more. I am trying to plot these values but since the elements of my lists are unequal to I receive a bounds exception.
Sample Data:
location_lat
[32.831, 32.831, 32.832, 32.832, 32.833, 32.833, 32.834, 32.834,
32.835, 32.835, 32.836, 32.836, 32.837, 32.837, 32.838]
location_long
[-96.691, -96.691, -96.692, -96.692, -96.693, -96.693, -96.694, -96.694,
-96.695, -96.695, -96.696, -96.696, -96.697, -96.697, -96.698]
wifi_Rssi
[-81, -81, -81, -81, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 0]
Code Snippet:
I strip off the brackets then . . .
wifiRssi <- opr$wifi_Rssi
wifiRssi <- gsub(" ", "", wifiRssi, fixed = TRUE)
wifiRssi <- strsplit(wifiRssi, ",")
wifiRssi <- unlist(wifiRssi)
wifiRssi <- as.integer(wifiRssi)
lat<- as.character(opr$location_lat)
lat<- gsub(" ", "", lat, fixed = TRUE)
lat<- strsplit(lat, ",")
lat<- unlist(lat)
lat<- as.double(lat)
long<- as.character(opr$location_long)
long<- gsub(" ", "", long, fixed = TRUE)
long<- strsplit(long, ",")
long<- unlist(long)
long<- as.double(long)
pal <- colorNumeric(c('red','green'), wifiSNR)
geoplots <- sp::SpatialPointsDataFrame(
cbind(long, lat),
data.frame(wifiRssi)
)
Error in validObject(.Object) : invalid class “SpatialPointsDataFrame” object: number of rows in data.frame and SpatialPoints don't match
What I want to be able to do is truncate the list to the smallest number of elements. For example, if wifiRSSI contained n elements and lat/long contained n+5 elements – then truncate lat/lon to the first n elements [1:n] to match wifiRSSI then plot.
Any ideas or suggestions would be appreciated.