Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Box-the-compass/R/box-the-compass-1.r
Normal file
20
Task/Box-the-compass/R/box-the-compass-1.r
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Build a table of directions
|
||||
pts <- data.frame(
|
||||
des = c("N", "NxE", "NNE", "NExN", "NE", "NExE", "ENE", "ExN",
|
||||
"E", "ExS", "ESE", "SExE", "SE", "SExS", "SSE", "SxE",
|
||||
"S", "SxW", "SSW", "SWxS", "SW", "SWxW", "WSW", "WxS",
|
||||
"W", "WxN", "WNW", "NWxW", "NW", "NWxN", "NNW", "NxW",
|
||||
"N")
|
||||
)
|
||||
pts$deg <- seq(0, 360, 360/32)
|
||||
|
||||
heading <- Vectorize(function(deg) {
|
||||
res <- pts
|
||||
# Calculate the absolute difference between each
|
||||
# point on the table and the function input
|
||||
res$diff <- abs(res$deg - deg)
|
||||
|
||||
# Sort the table by abs difference, return the first
|
||||
res <- res[order(res$diff), ]
|
||||
res[1,]$des[1]
|
||||
})
|
||||
10
Task/Box-the-compass/R/box-the-compass-2.r
Normal file
10
Task/Box-the-compass/R/box-the-compass-2.r
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
test <- data.frame(
|
||||
deg = c( 0.0, 16.87, 16.88, 33.75, 50.62, 50.63, 67.5, 84.37,
|
||||
84.38, 101.25, 118.12, 118.13, 135.0, 151.87, 151.88, 168.75,
|
||||
185.62, 185.63, 202.5, 219.37, 219.38, 236.25, 253.12, 253.13,
|
||||
270.0, 286.87, 286.88, 303.75, 320.62, 320.63, 337.5, 354.37,
|
||||
354.38)
|
||||
)
|
||||
|
||||
test$heading <- heading(test$deg)
|
||||
test
|
||||
1
Task/Box-the-compass/R/box-the-compass-3.r
Normal file
1
Task/Box-the-compass/R/box-the-compass-3.r
Normal file
|
|
@ -0,0 +1 @@
|
|||
all.equal(test$heading, pts$des)
|
||||
Loading…
Add table
Add a link
Reference in a new issue