@@ -57,7 +57,7 @@ isIn(x, LETTERS)
57
57
```
58
58
59
59
```
60
- ## [1] "B " "Y " "A " "T " "J "
60
+ ## [1] "I " "K " "S " "Y " "W "
61
61
```
62
62
But
63
63
@@ -68,7 +68,7 @@ isIn(c(x, "a"), LETTERS)
68
68
```
69
69
70
70
```
71
- ## [1] "B " "Y " "A " "T " "J " NA
71
+ ## [1] "I " "K " "S " "Y " "W " NA
72
72
```
73
73
74
74
### Solution
@@ -263,9 +263,37 @@ isExactIn(c("a", "z"), c("abc", letters))
263
263
## [1] "abc" "a"
264
264
```
265
265
266
- <!-- ### Solution -->
266
+ ### Solution
267
+
267
268
269
+ ``` r
270
+ # # Unit test:
271
+ library(" RUnit" )
272
+ test_isExactIn <- function () {
273
+ checkIdentical(" a" , isExactIn(" a" , letters ))
274
+ checkIdentical(" a" , isExactIn(" a" , c(" abc" , letters )))
275
+ checkIdentical(c(" a" , " z" ), isExactIn(c(" a" , " z" ), c(" abc" , letters )))
276
+ }
268
277
278
+ test_isExactIn()
279
+ ```
280
+
281
+ ```
282
+ ## Error in checkIdentical("a", isExactIn("a", c("abc", letters))): FALSE
283
+ ##
284
+ ```
285
+
286
+ ``` r
287
+ # # updated function:
288
+ isExactIn <- function (x , y )
289
+ x [x %in% y ]
290
+
291
+ test_isExactIn()
292
+ ```
293
+
294
+ ```
295
+ ## [1] TRUE
296
+ ```
269
297
270
298
## If conditions with length > 1
271
299
@@ -387,12 +415,12 @@ y <- rnorm(5)
387
415
```
388
416
389
417
```
390
- ## x y
391
- ## [1,] 2.301199 0.60939751
392
- ## [2,] 1.380715 1.49984771
393
- ## [3,] 1.237685 0.58034293
394
- ## [4,] -1.723762 -0.45066731
395
- ## [5,] -1.389801 -0.05480788
418
+ ## x y
419
+ ## [1,] -3.1164934 -1.81741540
420
+ ## [2,] 1.5741209 -0.05377479
421
+ ## [3,] -0.6298675 0.68829382
422
+ ## [4,] -1.3595685 -1.09019047
423
+ ## [5,] 0.9666774 0.76398426
396
424
```
397
425
398
426
``` r
@@ -401,15 +429,15 @@ y <- rnorm(5)
401
429
402
430
```
403
431
## x y
404
- ## 2.3011991 0.6093975
432
+ ## -3.116493 -1.817415
405
433
```
406
434
407
435
``` r
408
436
distances(p , m )
409
437
```
410
438
411
439
```
412
- ## [1] 0.000000 1.280700 1.063910 4.162217 3.750287
440
+ ## [1] 0.000000 5.011217 3.530140 1.901484 4.830725
413
441
```
414
442
415
443
``` r
@@ -418,21 +446,21 @@ distances(p, m)
418
446
```
419
447
420
448
```
421
- ## x y
422
- ## 1 2.301199 0.60939751
423
- ## 2 1.380715 1.49984771
424
- ## 3 1.237685 0.58034293
425
- ## 4 -1.723762 -0.45066731
426
- ## 5 -1.389801 -0.05480788
449
+ ## x y
450
+ ## 1 -3.1164934 -1.81741540
451
+ ## 2 1.5741209 -0.05377479
452
+ ## 3 -0.6298675 0.68829382
453
+ ## 4 -1.3595685 -1.09019047
454
+ ## 5 0.9666774 0.76398426
427
455
```
428
456
429
457
``` r
430
458
(q <- dd [1 , ])
431
459
```
432
460
433
461
```
434
- ## x y
435
- ## 1 2.301199 0.6093975
462
+ ## x y
463
+ ## 1 -3.116493 -1.817415
436
464
```
437
465
438
466
``` r
0 commit comments