Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
8
Task/Extend-your-language/R/extend-your-language-1.r
Normal file
8
Task/Extend-your-language/R/extend-your-language-1.r
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
if2 <- function(condition1, condition2, both_true, first_true, second_true, both_false)
|
||||
{
|
||||
expr <- if(condition1)
|
||||
{
|
||||
if(condition2) both_true else first_true
|
||||
} else if(condition2) second_true else both_false
|
||||
eval(expr)
|
||||
}
|
||||
12
Task/Extend-your-language/R/extend-your-language-2.r
Normal file
12
Task/Extend-your-language/R/extend-your-language-2.r
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
for(x in 1:2) for(y in letters[1:2])
|
||||
{
|
||||
print(if2(x == 1, y == "a",
|
||||
"both conditions are true",
|
||||
x + 99,
|
||||
{
|
||||
yy <- rep.int(y, 10)
|
||||
paste(letters[1:10], yy)
|
||||
},
|
||||
NULL
|
||||
))
|
||||
}
|
||||
10
Task/Extend-your-language/R/extend-your-language-3.r
Normal file
10
Task/Extend-your-language/R/extend-your-language-3.r
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
if2 <- function(condition1, condition2, expr_list = NULL)
|
||||
{
|
||||
cl <- as.call(expr_list)
|
||||
cl_name <- if(condition1)
|
||||
{
|
||||
if(condition2) "" else "else1"
|
||||
} else if(condition2) "else2" else "else"
|
||||
if(!nzchar(cl_name)) cl_name <- which(!nzchar(names(cl)))
|
||||
eval(cl[[cl_name]])
|
||||
}
|
||||
13
Task/Extend-your-language/R/extend-your-language-4.r
Normal file
13
Task/Extend-your-language/R/extend-your-language-4.r
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
for(x in 1:2) for(y in letters[1:2])
|
||||
{
|
||||
print(if2(x == 1, y == "a", list(
|
||||
"both conditions are true",
|
||||
else1 = x + 99,
|
||||
else2 =
|
||||
{
|
||||
yy <- rep.int(y, 10)
|
||||
paste(letters[1:10], yy)
|
||||
},
|
||||
"else" = NULL
|
||||
)))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue