Bicho<-function(Modal,Num,Aposta,Cercar){ valores<-sample(0:9999,size = 5,replace = FALSE,prob = NULL) valor1<-as.character(valores[1]) valor2<-as.character(valores[2]) valor3<-as.character(valores[3]) valor4<-as.character(valores[4]) valor5<-as.character(valores[5]) library(stringr) if(str_length(valor1)<4){ valor1<-str_pad(valor1,width = 4,side = "left",pad = "0") } if(str_length(valor2)<4){ valor2<-str_pad(valor2,width = 4,side = "left",pad = "0") } if(str_length(valor3)<4){ valor3<-str_pad(valor3,width = 4,side = "left",pad = "0") } if(str_length(valor4)<4){ valor4<-str_pad(valor4,width = 4,side = "left",pad = "0") } if(str_length(valor5)<4){ valor5<-str_pad(valor5,width = 4,side = "left",pad = "0") } Num<-as.character(Num) if(Cercar==TRUE){ if(Modal=="Dezena" | Modal=="dezena" | Modal=="DEZENA"){ if(str_sub(Num,start=3)==str_sub(valor1,start=3) | str_sub(Num,start=3)==str_sub(valor2,start=3) | str_sub(Num,start=3)==str_sub(valor3,start=3) | str_sub(Num,start=3)==str_sub(valor4,start=3) | str_sub(Num,start=3)==str_sub(valor5,start=3)){ prize<-Aposta*12 } else{ prize<-0 } } if(Modal=="Centena" | Modal=="centena" | Modal=="CENTENA"){ if(str_sub(Num,start=2)==str_sub(valor1,start=2) | str_sub(Num,start=2)==str_sub(valor2,start=2) | str_sub(Num,start=2)==str_sub(valor3,start=2) | str_sub(Num,start=2)==str_sub(valor4,start=2) | str_sub(Num,start=2)==str_sub(valor5,start=2)){ prize<-Aposta*120 } else{ prize<-0 } } if(Modal=="Milhar" | Modal=="milhar" | Modal=="MILHAR"){ if(Num==valor1 | Num==valor2 | Num==valor3 | Num==valor4 | Num==valor5){ prize<-Aposta*800 } else{ prize<-0 } } } if(Cercar==FALSE){ if(Modal=="Dezena" | Modal=="dezena" | Modal=="DEZENA"){ if(str_sub(Num,start=3)==str_sub(valor1,start=3)){ prize<-Aposta*60 } else{ prize<-0 } } if(Modal=="Centena" | Modal=="centena" | Modal=="CENTENA"){ if(str_sub(Num,start=2)==str_sub(valor1,start=2)){ prize<-Aposta*600 } else{ prize<-0 } } if(Modal=="Milhar" | Modal=="milhar" | Modal=="MILHAR"){ if(Num==valor1){ prize<-Aposta*4000 } else{ prize<-0 } } } if(prize!=0){ return(prize) } else{ return (-Aposta) } }
Write, Run & Share R Language code online using OneCompiler's R Language online compiler for free. It's one of the robust, feature-rich online compilers for R language, running on the latest version 3.4. Getting started with the OneCompiler's R Language compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as R
and start coding.
R is very popular for data analytics which was created by Ross Ihaka and Robert Gentleman in 1993. Many big companies like Google, Facebook, Airbnb etc uses this language for data analytics. R is good for software developers, statisticians and data miners.
Data type | Description | Usage |
---|---|---|
Numeric | To represent decimal values | x=1.84 |
Integer | To represent integer values, L tells to store the value as integer | x=10L |
Complex | To represent complex values | x = 10+2i |
Logical | To represent boolean values, true or false | x = TRUE |
Character | To represent string values | x <- "One compiler" |
raw | Holds raw bytes |
Variables can be assigned using any of the leftward, rightward or equal to operator. You can print the variables using either print or cat functions.
var-name = value
var-name <- value
value -> var-name
If, If-else, Nested-Ifs are used when you want to perform a certain set of operations based on conditional expressions.
if(conditional-expression){
#code
}
if(conditional-expression){
#code if condition is true
} else {
#code if condition is false
}
if(condition-expression1) {
#code if above condition is true
} elseif(condition-expression2){
#code if above condition is true
}
elseif(condition-expression3) {
#code if above condition is true
}
...
else {
#code if all the conditions are false
}
Switch is used to execute one set of statement from multiple conditions.
switch(expression, case-1, case-2, case-3....)
For loop is used to iterate a set of statements based on a condition.
for (value in vector) {
# code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while(condition) {
# code
}
Repeat is used tyo iterate a set of statements with out any condition. You can write a user-defined condition to exit from the loop using IF
.
repeat {
#code
if(condition-expression) {
break
}
}
Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
func-name <- function(parameter_1, parameter_2, ...) {
#code for function body
}
function_name (parameters)
Vector is a basic data strucre where sequence of data values share same data type.
For example, the below statement assigns 1 to 10 values to x.
You can also use se() function to create vectors.
x <- 1:10
#using seq() function
x <- seq(1, 10, by=2)
the above statement prints the output as [1] 1 3 5 7 9
.