SlideShare a Scribd company logo
 x <- 41
 if (x > 10) {
 print("Above ten")
 if (x > 20) {
 print("and also above 20!")
 } else {
 print("but not above 20.")
 }
 } else {
 print("below 10.")
 }
 [1] "Above ten"
[1] "and also above 20!"
 x<-5
 if(is.nan(x))
 {
 message("x is missing")
 } else if(is.infinite(x))
 {
 message("x is infinite")
 } else if(x > 0)
 {
 message("x is positive")
 } else if(x < 0)
 {
 message("x is negative")
 } else
 {
 message("x is zero")
 }
Loop
 There are three kinds of loops in R:
 Repeat
 While, and for
 they can still come in handy for repeatedly executing code
 Repeat:
 i<-0
 repeat
 {
 print(i)
 i<-i+1
 if(i>=3)
 break
 }
While
 i<-1
 While (i<=4)
 {
 i<-i+1
 print(i)
 }
 Output:
 2
 3
 4
 5
For loop
 for(i in seq(1,10,2))
 { print(i) }
 i<-1
 for(j in 1:3)
 {
 i<-i+1
 print(i)
 }
 Output:
 2
 3
 4
Functions
 A function is a block of code which only runs when
it is called.
 You can pass data, known as parameters, into a
function.
 A function can return data as a result.
Creating and Calling Function in R
 In order to understand functions better, let’s take a look
at what they consist of.
 Typing the name of a function shows you the code that
runs when you call it.
 The terms "parameter" and "argument" can be used for the
same thing: information that are passed into a function.
 From a function's perspective:
 A parameter is the variable listed inside the parentheses
in the function definition.
 An argument is the value that is sent to the function when
it is called.
Example
 Sample<-function(a,b,c)
 {
 print(a)
print(b)
print(c)
print(a+b+c)
}
Sample(2,3,4)
Passing Functions to and from Other
Functions
 Functions can be used just like other variable
types, so we can pass them as arguments to other
functions, and return them from functions.
 One common example of a function that takes
another function as an argument is do.call.
 do.call(function(x, y) x + y, list(1:5, 5:1))
 ## [1] 6 6 6 6 6
do.call()
#create three data frames
df1 <- data.frame(team=c('A', 'B', 'C'), points=c(22, 27, 38))
df2 <- data.frame(team=c('D', 'E', 'F'), points=c(22, 14, 20))
df3 <- data.frame(team=c('G', 'H', 'I'), points=c(11, 15, 18))
#place three data frames into list
df_list <- list(df1, df2, df3)
#row bind together all three data frames
do.call(rbind, df_list)
Variable Scope
 A variable’s scope is the set of places from which you can see the variable.
For example, when you define a variable inside a function, the rest of the
statements in that function will have access to that variable.
 In R subfunctions will also have access to that variable.
 In this next example, the function f takes a variable x and passes it to the
function g. f also defines a variable y, which is within the scope of g, since g
is a sub‐ function of f.
 So, even though y isn’t defined inside g, the example works:
 f <- function(x)
 {
 y <- 1
 g <- function(x)
 {
 (x + y) / 2 #y is used, but is not a formal argument of g }
 g(x)
 }
 f(sqrt(5)) #It works! y is magically found in the environment of f
 ## [1] 1.618
String Manipulation
 String manipulation basically refers to the process of
handling and analyzing strings.
 It involves various operations concerned with
modification and parsing of strings to use and change its
data.
 Paste:
 str <- paste(c(1:3), "4", sep = ":")
 print (str)
 ## "1:4" "2:4" "3:4"
 Concatenation:
 # Concatenation using cat() function
 str <- cat("learn", "code", "tech", sep = ":")
 print (str)
## learn:code:tech
Packages and Visualization
Loading and Packages
 R is not limited to the code provided by the R Core Team.
It is very much a community effort, and
 there are thousands of add-on packages available to
extend it.
 The majority of R packages are currently installed in an
online repository called CRAN (the Comprehensive R
Archive Network1)
 which is maintained by the R Core Team. Installing and
using these add-on packages is an important part of the R
experience
Loading Packages
 To load a package that is already installed on your
machine, you call the library function
 We can load it with the library function:
 library(lattice)
 the functions provided by lattice. For example,
displays a fancy dot plot of the famous Immer’s barley
dataset:
dotplot(
variety ~ yield | site,
data = barley,
groups = year
)
Scatter Plot
 A "scatter plot" is a type of plot used to display the relationship between two
numerical variables, and plots one dot for each observation.
 It needs two vectors of same length, one for the x-axis (horizontal) and one
for the y-axis (vertical):
 Example
 x <- c(5,7,8,7,2,2,9,4,11,12,9,6)
y <- c(99,86,87,88,111,103,87,94,78,77,85,86)
plot(x, y)
P<- ggplot(mtcars,aes(wt,mpg) )
p+geom_point()
P<- ggplot(mtcars,aes(wt,mpg) )
p+geom_line(color=blue)
Box_plot()
ggplot(data = mpg, aes(x = drv, y = hwy,
colour = class)) +
geom_boxplot()
Geom_bar()
g <- ggplot(mpg, aes(class))
# Number of cars in each class:
g + geom_bar()

More Related Content

Similar to 世预赛投注-世预赛投注投注官网app-世预赛投注官网app下载|【​网址​🎉ac123.net🎉​】 (20)

PPTX
欧洲杯买球-欧洲杯买球猜球-欧洲杯买球猜球网站|【​网址​🎉ac10.net🎉​】
barajasfr42922
 
PPTX
世预赛投注-世预赛投注网投官网-世预赛投注投注网站|【​网址​🎉ac10.net🎉​】
2nhqvmvs9te2ak8v
 
PPTX
世预赛下注-世预赛下注比赛投注官网-世预赛下注投注官网app|【​网址​🎉ac44.net🎉​】
coueyrichh51723
 
PPTX
欧洲杯体彩-欧洲杯体彩足彩-欧洲杯体彩足彩竞猜|【​网址​🎉ac55.net🎉​】
juliancopeman444
 
PPTX
世预赛下注-世预赛下注投注-世预赛下注投注网|【​网址​🎉ac10.net🎉​】
trishahafez481
 
PPTX
nba-nba买球推荐-nba买球推荐网站|【​网址​🎉ac10.net🎉​】
balliuvilla512
 
PPTX
欧洲杯投注-欧洲杯投注押注app-欧洲杯投注押注app官网|【​网址​🎉ac10.net🎉​】
akrooshsaleem36
 
PPTX
欧洲杯买球-欧洲杯买球买球推荐-欧洲杯买球买球推荐网站|【​网址​🎉ac10.net🎉​】
concepsionchomo153
 
PPTX
欧洲杯下注-欧洲杯下注投注官网app-欧洲杯下注哪里有正规的买球网站|【​网址​🎉ac55.net🎉​】
siomaranico724
 
PPTX
世预赛买球-世预赛买球下注平台-世预赛买球投注平台|【​网址​🎉ac10.net🎉​】
terkesimamishy540
 
PPTX
欧洲杯赌球-欧洲杯赌球竞猜官网-欧洲杯赌球竞猜网站|【​网址​🎉ac10.net🎉​】
juliancopeman444
 
PPTX
欧洲杯赌钱-欧洲杯赌钱足彩竞猜-欧洲杯赌钱竞猜app|【​网址​🎉ac123.net🎉​】
stellacovaleda199
 
PPTX
欧洲杯赌球-欧洲杯赌球买球官方官网-欧洲杯赌球比赛投注官网|【​网址​🎉ac55.net🎉​】
valvereliz227
 
PPTX
世预赛买球-世预赛买球买球网-世预赛买球买球网站|【​网址​🎉ac22.net🎉​】
valvereliz227
 
PPTX
欧洲杯足彩-欧洲杯足彩下注网站-欧洲杯足彩投注网站|【​网址​🎉ac99.net🎉​】
humbertogarsia692
 
PPTX
世预赛下注-世预赛下注竞猜网站-世预赛下注竞猜波胆|【​网址​🎉ac123.net🎉​】
sawyerhenriquez126
 
PPTX
欧洲杯买球-欧洲杯买球买球网好的网站-欧洲杯买球哪里有正规的买球网站|【​网址​🎉ac123.net🎉​】
jafiradnan336
 
PPTX
欧洲杯投注-欧洲杯投注买球网站-欧洲杯投注买球网址|【​网址​🎉ac123.net🎉​】
irisvladislava756
 
PPTX
美洲杯下注-美洲杯下注最好的投注软件-美洲杯下注在哪个软件买球|【​网址​🎉ac22.net🎉​】
velosonando62
 
PPTX
欧洲杯足彩-欧洲杯足彩体彩-欧洲杯足彩竞彩|【​网址​🎉ac44.net🎉​】
hanniaarias53
 
欧洲杯买球-欧洲杯买球猜球-欧洲杯买球猜球网站|【​网址​🎉ac10.net🎉​】
barajasfr42922
 
世预赛投注-世预赛投注网投官网-世预赛投注投注网站|【​网址​🎉ac10.net🎉​】
2nhqvmvs9te2ak8v
 
世预赛下注-世预赛下注比赛投注官网-世预赛下注投注官网app|【​网址​🎉ac44.net🎉​】
coueyrichh51723
 
欧洲杯体彩-欧洲杯体彩足彩-欧洲杯体彩足彩竞猜|【​网址​🎉ac55.net🎉​】
juliancopeman444
 
世预赛下注-世预赛下注投注-世预赛下注投注网|【​网址​🎉ac10.net🎉​】
trishahafez481
 
nba-nba买球推荐-nba买球推荐网站|【​网址​🎉ac10.net🎉​】
balliuvilla512
 
欧洲杯投注-欧洲杯投注押注app-欧洲杯投注押注app官网|【​网址​🎉ac10.net🎉​】
akrooshsaleem36
 
欧洲杯买球-欧洲杯买球买球推荐-欧洲杯买球买球推荐网站|【​网址​🎉ac10.net🎉​】
concepsionchomo153
 
欧洲杯下注-欧洲杯下注投注官网app-欧洲杯下注哪里有正规的买球网站|【​网址​🎉ac55.net🎉​】
siomaranico724
 
世预赛买球-世预赛买球下注平台-世预赛买球投注平台|【​网址​🎉ac10.net🎉​】
terkesimamishy540
 
欧洲杯赌球-欧洲杯赌球竞猜官网-欧洲杯赌球竞猜网站|【​网址​🎉ac10.net🎉​】
juliancopeman444
 
欧洲杯赌钱-欧洲杯赌钱足彩竞猜-欧洲杯赌钱竞猜app|【​网址​🎉ac123.net🎉​】
stellacovaleda199
 
欧洲杯赌球-欧洲杯赌球买球官方官网-欧洲杯赌球比赛投注官网|【​网址​🎉ac55.net🎉​】
valvereliz227
 
世预赛买球-世预赛买球买球网-世预赛买球买球网站|【​网址​🎉ac22.net🎉​】
valvereliz227
 
欧洲杯足彩-欧洲杯足彩下注网站-欧洲杯足彩投注网站|【​网址​🎉ac99.net🎉​】
humbertogarsia692
 
世预赛下注-世预赛下注竞猜网站-世预赛下注竞猜波胆|【​网址​🎉ac123.net🎉​】
sawyerhenriquez126
 
欧洲杯买球-欧洲杯买球买球网好的网站-欧洲杯买球哪里有正规的买球网站|【​网址​🎉ac123.net🎉​】
jafiradnan336
 
欧洲杯投注-欧洲杯投注买球网站-欧洲杯投注买球网址|【​网址​🎉ac123.net🎉​】
irisvladislava756
 
美洲杯下注-美洲杯下注最好的投注软件-美洲杯下注在哪个软件买球|【​网址​🎉ac22.net🎉​】
velosonando62
 
欧洲杯足彩-欧洲杯足彩体彩-欧洲杯足彩竞彩|【​网址​🎉ac44.net🎉​】
hanniaarias53
 

More from bljeremy734 (9)

PPT
欧洲杯投注网站信誉网站-欧洲杯投注网站平台网站大全 |【​网址​🎉ac55.net🎉​】 .
bljeremy734
 
PPT
推荐十大正规欧洲杯投注app网站-欧洲杯投注app |【​网址​🎉ac123.net🎉​】
bljeremy734
 
PPT
2024欧洲杯赔率-2024欧洲杯赔率押注怎么玩-网上怎么押注2024欧洲杯赔率 |【​网址​🎉ac22.net🎉​】
bljeremy734
 
PPT
欧洲杯投注网站-欧洲杯投注网站赛程-欧洲杯投注网站压注 |【​网址​🎉ac22.net🎉​】
bljeremy734
 
PPTX
欧洲杯足彩-欧洲杯足彩买球-欧洲杯足彩买球网|【​网址​🎉ac99.net🎉​】
bljeremy734
 
PPTX
欧洲杯足彩-欧洲杯足彩比赛投注-欧洲杯足彩比赛投注官网|【​网址​🎉ac10.net🎉​】
bljeremy734
 
PPTX
美洲杯买球-美洲杯买球投注竞彩-美洲杯买球竞猜投注|【​网址​🎉ac10.net🎉​】
bljeremy734
 
PPTX
世预赛买球-世预赛买球比赛投注-世预赛买球比赛投注官网|【​网址​🎉ac10.net🎉​】
bljeremy734
 
PDF
欧洲杯开户-信誉的欧洲杯开户-正规欧洲杯开户|【​网址​🎉ac123.net🎉​】
bljeremy734
 
欧洲杯投注网站信誉网站-欧洲杯投注网站平台网站大全 |【​网址​🎉ac55.net🎉​】 .
bljeremy734
 
推荐十大正规欧洲杯投注app网站-欧洲杯投注app |【​网址​🎉ac123.net🎉​】
bljeremy734
 
2024欧洲杯赔率-2024欧洲杯赔率押注怎么玩-网上怎么押注2024欧洲杯赔率 |【​网址​🎉ac22.net🎉​】
bljeremy734
 
欧洲杯投注网站-欧洲杯投注网站赛程-欧洲杯投注网站压注 |【​网址​🎉ac22.net🎉​】
bljeremy734
 
欧洲杯足彩-欧洲杯足彩买球-欧洲杯足彩买球网|【​网址​🎉ac99.net🎉​】
bljeremy734
 
欧洲杯足彩-欧洲杯足彩比赛投注-欧洲杯足彩比赛投注官网|【​网址​🎉ac10.net🎉​】
bljeremy734
 
美洲杯买球-美洲杯买球投注竞彩-美洲杯买球竞猜投注|【​网址​🎉ac10.net🎉​】
bljeremy734
 
世预赛买球-世预赛买球比赛投注-世预赛买球比赛投注官网|【​网址​🎉ac10.net🎉​】
bljeremy734
 
欧洲杯开户-信誉的欧洲杯开户-正规欧洲杯开户|【​网址​🎉ac123.net🎉​】
bljeremy734
 
Ad

Recently uploaded (20)

PDF
Development of Portable Spectometer For MIlk Qulaity analysis
ppr9495
 
PPT
Confined Space.ppth. Bbbb. Bbbbbbbbbbbbbbbbbbbbbbbnnnjjj
eshaiqbal7
 
PPTX
Series.pptxvvggghgufifudududydydydudyxyxyx
jasperbernaldo3
 
PPTX
怎么办StoutLetter美国威斯康星大学斯托特分校本科毕业证,Stout学历证书
Taqyea
 
PPTX
英国学位证(LTU毕业证书)利兹三一大学毕业证书如何办理
Taqyea
 
PPTX
diagnosisinfpdpart1-200628063900 (1).pptx
JayeshTaneja4
 
PPTX
ualities-of-Quantitative-Research-1.pptx
jamjamkyong
 
PDF
Utility Software hshdgsvcjdgvbdvcfkcdgdc
imeetrinidadfuertesa
 
PPTX
原版澳洲莫道克大学毕业证(MU毕业证书)如何办理
Taqyea
 
PPT
it_14.ppt using atharva college of engineering
shkzishan810
 
PPT
Computer Hardware and Software Hw and SW .ppt
MuzaFar28
 
PPT
(1) Chemotherapeutic drugs Antimicrobials.ppt
mkurdi133
 
PPTX
Flannel graphFlannel graphFlannel graphFlannel graphFlannel graph
shareesh25
 
PDF
Elevator Maintenance Checklist with eAuditor Audits & Inspections
eAuditor Audits & Inspections
 
PPTX
西班牙维尔瓦大学电子版毕业证{UHU毕业完成信UHU水印成绩单}原版制作
Taqyea
 
PPTX
哪里购买澳洲学历认证查询伊迪斯科文大学成绩单水印ECU录取通知书
Taqyea
 
PPTX
Contingency-Plan-and-Reminders-from-the-PMO.pptx
PrincessCamilleGalle1
 
PPTX
Dock Line Organization Made Easy – Discover AMARREX, the Mooring Line Holder ...
Seawatt
 
PPTX
英国学位证(PSU毕业证书)普利茅斯大学毕业证书如何办理
Taqyea
 
PPTX
一比一原版(UoB毕业证)布莱德福德大学毕业证如何办理
Taqyea
 
Development of Portable Spectometer For MIlk Qulaity analysis
ppr9495
 
Confined Space.ppth. Bbbb. Bbbbbbbbbbbbbbbbbbbbbbbnnnjjj
eshaiqbal7
 
Series.pptxvvggghgufifudududydydydudyxyxyx
jasperbernaldo3
 
怎么办StoutLetter美国威斯康星大学斯托特分校本科毕业证,Stout学历证书
Taqyea
 
英国学位证(LTU毕业证书)利兹三一大学毕业证书如何办理
Taqyea
 
diagnosisinfpdpart1-200628063900 (1).pptx
JayeshTaneja4
 
ualities-of-Quantitative-Research-1.pptx
jamjamkyong
 
Utility Software hshdgsvcjdgvbdvcfkcdgdc
imeetrinidadfuertesa
 
原版澳洲莫道克大学毕业证(MU毕业证书)如何办理
Taqyea
 
it_14.ppt using atharva college of engineering
shkzishan810
 
Computer Hardware and Software Hw and SW .ppt
MuzaFar28
 
(1) Chemotherapeutic drugs Antimicrobials.ppt
mkurdi133
 
Flannel graphFlannel graphFlannel graphFlannel graphFlannel graph
shareesh25
 
Elevator Maintenance Checklist with eAuditor Audits & Inspections
eAuditor Audits & Inspections
 
西班牙维尔瓦大学电子版毕业证{UHU毕业完成信UHU水印成绩单}原版制作
Taqyea
 
哪里购买澳洲学历认证查询伊迪斯科文大学成绩单水印ECU录取通知书
Taqyea
 
Contingency-Plan-and-Reminders-from-the-PMO.pptx
PrincessCamilleGalle1
 
Dock Line Organization Made Easy – Discover AMARREX, the Mooring Line Holder ...
Seawatt
 
英国学位证(PSU毕业证书)普利茅斯大学毕业证书如何办理
Taqyea
 
一比一原版(UoB毕业证)布莱德福德大学毕业证如何办理
Taqyea
 
Ad

世预赛投注-世预赛投注投注官网app-世预赛投注官网app下载|【​网址​🎉ac123.net🎉​】

  • 1.  x <- 41  if (x > 10) {  print("Above ten")  if (x > 20) {  print("and also above 20!")  } else {  print("but not above 20.")  }  } else {  print("below 10.")  }  [1] "Above ten" [1] "and also above 20!"
  • 2.  x<-5  if(is.nan(x))  {  message("x is missing")  } else if(is.infinite(x))  {  message("x is infinite")  } else if(x > 0)  {  message("x is positive")  } else if(x < 0)  {  message("x is negative")  } else  {  message("x is zero")  }
  • 3. Loop  There are three kinds of loops in R:  Repeat  While, and for  they can still come in handy for repeatedly executing code  Repeat:  i<-0  repeat  {  print(i)  i<-i+1  if(i>=3)  break  }
  • 4. While  i<-1  While (i<=4)  {  i<-i+1  print(i)  }  Output:  2  3  4  5
  • 5. For loop  for(i in seq(1,10,2))  { print(i) }  i<-1  for(j in 1:3)  {  i<-i+1  print(i)  }  Output:  2  3  4
  • 6. Functions  A function is a block of code which only runs when it is called.  You can pass data, known as parameters, into a function.  A function can return data as a result.
  • 7. Creating and Calling Function in R  In order to understand functions better, let’s take a look at what they consist of.  Typing the name of a function shows you the code that runs when you call it.  The terms "parameter" and "argument" can be used for the same thing: information that are passed into a function.  From a function's perspective:  A parameter is the variable listed inside the parentheses in the function definition.  An argument is the value that is sent to the function when it is called.
  • 8. Example  Sample<-function(a,b,c)  {  print(a) print(b) print(c) print(a+b+c) } Sample(2,3,4)
  • 9. Passing Functions to and from Other Functions  Functions can be used just like other variable types, so we can pass them as arguments to other functions, and return them from functions.  One common example of a function that takes another function as an argument is do.call.  do.call(function(x, y) x + y, list(1:5, 5:1))  ## [1] 6 6 6 6 6
  • 10. do.call() #create three data frames df1 <- data.frame(team=c('A', 'B', 'C'), points=c(22, 27, 38)) df2 <- data.frame(team=c('D', 'E', 'F'), points=c(22, 14, 20)) df3 <- data.frame(team=c('G', 'H', 'I'), points=c(11, 15, 18)) #place three data frames into list df_list <- list(df1, df2, df3) #row bind together all three data frames do.call(rbind, df_list)
  • 11. Variable Scope  A variable’s scope is the set of places from which you can see the variable. For example, when you define a variable inside a function, the rest of the statements in that function will have access to that variable.  In R subfunctions will also have access to that variable.  In this next example, the function f takes a variable x and passes it to the function g. f also defines a variable y, which is within the scope of g, since g is a sub‐ function of f.
  • 12.  So, even though y isn’t defined inside g, the example works:  f <- function(x)  {  y <- 1  g <- function(x)  {  (x + y) / 2 #y is used, but is not a formal argument of g }  g(x)  }  f(sqrt(5)) #It works! y is magically found in the environment of f  ## [1] 1.618
  • 13. String Manipulation  String manipulation basically refers to the process of handling and analyzing strings.  It involves various operations concerned with modification and parsing of strings to use and change its data.  Paste:  str <- paste(c(1:3), "4", sep = ":")  print (str)  ## "1:4" "2:4" "3:4"  Concatenation:  # Concatenation using cat() function  str <- cat("learn", "code", "tech", sep = ":")  print (str) ## learn:code:tech
  • 15. Loading and Packages  R is not limited to the code provided by the R Core Team. It is very much a community effort, and  there are thousands of add-on packages available to extend it.  The majority of R packages are currently installed in an online repository called CRAN (the Comprehensive R Archive Network1)  which is maintained by the R Core Team. Installing and using these add-on packages is an important part of the R experience
  • 16. Loading Packages  To load a package that is already installed on your machine, you call the library function  We can load it with the library function:  library(lattice)  the functions provided by lattice. For example, displays a fancy dot plot of the famous Immer’s barley dataset: dotplot( variety ~ yield | site, data = barley, groups = year )
  • 17. Scatter Plot  A "scatter plot" is a type of plot used to display the relationship between two numerical variables, and plots one dot for each observation.  It needs two vectors of same length, one for the x-axis (horizontal) and one for the y-axis (vertical):  Example  x <- c(5,7,8,7,2,2,9,4,11,12,9,6) y <- c(99,86,87,88,111,103,87,94,78,77,85,86) plot(x, y)
  • 20. Box_plot() ggplot(data = mpg, aes(x = drv, y = hwy, colour = class)) + geom_boxplot()
  • 21. Geom_bar() g <- ggplot(mpg, aes(class)) # Number of cars in each class: g + geom_bar()