[datatable-help] Using apply over two data frames with destPoint function

pedropumpalot jgarrigan at gmail.com
Fri Nov 4 01:32:11 CET 2016


Hi,

How can I use apply function in conjunction with the destPoint function from
the geosphere package across two data frames?

I have tried the following but I am getting an error

classEndPoints <- t(apply(DF1[,c(7:8,64:70)],DF2[,c(1:2)],1, function(x)
destPoint(x[1:2],x[3:9],x[10:11])))

I get the following error: Error in match.fun(FUN) : '1' is not a function,
character or symbol

I have lat and long coordinates in DF1 in columns 7 & 8 and bearings (B1-B7)
in columns 64 to 70

Lat             Long       .....   B1 B2  B3  B4  B5   B6  B7 
-8.609117  52.69373 .....  10 20   30  40  50   60  70
-8.607815  52.69444 .....  80 90 100 110 120 130 140

In my other data frame DF2 I have 21 rows of data across 2 columns. 


Class    From   To
Class 0    0   234
Class 1   234  468
Class 2   468  936
    .
    .
Class 20  1500 2500

I wish to use this data with the destPoint function which takes the form
destPoint(p, b, d) where p is a vector or matrix of long and latitude, b is
a single bearing and d is a distance.

I would like to calculate the destPoint function for each row of data as
follows:

destPoint(-8.609117 52.69373,10, 0)
destPoint(-8.609117 52.69373,20, 0)
destPoint(-8.609117 52.69373,30, 0)
              .
              .
              .
destPoint(-8.609117 52.69373,70, 0)
destPoint(-8.609117 52.69373,10, 234)
destPoint(-8.609117 52.69373,20, 234)
              .
              .
destPoint(-8.609117 52.69373,70, 234)
destPoint(-8.609117 52.69373,10, 234)
destPoint(-8.609117 52.69373,20, 234)
              .
              .
destPoint(-8.609117 52.69373,70, 234)
destPoint(-8.609117 52.69373,10, 468)
              .
              .
destPoint(-8.609117 52.69373,70, 468)  
destPoint(-8.609117 52.69373,10, 468)
              .
              .
destPoint(-8.609117 52.69373,70, 468)
destPoint(-8.609117 52.69373,10, 936)
              .
              .
destPoint(-8.609117 52.69373,70, 936)

Can anyone help me in the approach to this problem, please note I am still
getting to grips with R so go gentle!!



--
View this message in context: http://r.789695.n4.nabble.com/Using-apply-over-two-data-frames-with-destPoint-function-tp4726187.html
Sent from the datatable-help mailing list archive at Nabble.com.


More information about the datatable-help mailing list