SlideShare a Scribd company logo
1 of 22
Download to read offline
Kan, Hao-Cheng
Lunghwa University of Science and Technology
http://kanchengzxdfgcv.blogspot.tw/
> as.numeric(TRUE)
> as.numeric(FALSE)
> as.character(TRUE)
> as.character(FALSE)
> as.factor(TRUE)
> as.factor(FALSE)
>
> k = "kan"
> class(k)
> as.character(k)
>
> n = 123
> class(n)
> as.numeric(n)
>
> test = as.numeric(k)
> test
> 1 == 1
> 1 < 1
> 1 <= 1
> 1 > 1
> 1 >= 1
> 1 != 1
> toCheck = 1
if (toCheck == 1)
{
print("hello")
}
if (toCheck == 0)
{
print("hello")
}
check.bool = function(x){
if (x == 1){
print("hello")
}else{
print("goodbye")
}
}
> check.bool(1)
> check.bool(0)
> check.bool("k")
> check.bool(TRUE)
check.bool = function(x){
if (x == 1){
print("hello")
} else if (x == 0){
print("goodbye")
} else{
print("confused")
}
}
> check.bool(1)
> check.bool(0)
> check.bool(2)
> check.bool("k")
use.switch = function(x){
switch(x,
"a"="first",
"b"="second",
"z"="last",
"c"="third",
"other")
}
> use.switch("a")
> use.switch("b")
> use.switch("c")
> use.switch("d")
> use.switch("OwO")
> use.switch("z")
> use.switch(1)
> use.switch(2)
> use.switch(3)
> use.switch(4)
> use.switch(5)
> use.switch(6)
> is.null(use.switch(6))
> ifelse(1 == 1, "Yes", "No")
> ifelse(1 == 0, "Yes", "No")
>
> toTest = c(1, 1, 0, 1, 0, 1)
> class(toTest)
> toTest
>
> ifelse(toTest == 1, "Yes", "No")
> ifelse(toTest == 1, toTest * 3, toTest)
> ifelse(toTest == 1, toTest * 3, "Zero")
>
> toTest[2] = NA
> class(toTest)
> toTest
>
> ifelse(toTest == 1, "Yes", "No")
> ifelse(toTest == 1, toTest * 3, toTest)
> ifelse(toTest == 1, toTest * 3, "Zero")
> a = c(1, 1, 0, 1)
> b = c(2, 1, 0, 1)
> bs = c(2, 1, 0, 1)
>
> ifelse(a == 1 & b == 1, "Yes", "No")
> ifelse(a == 1 && b == 1, "Yes", "No")
> ifelse(a == 1 && bs == 1, "Yes", "No")
ifelse(a == 1 & b == 1, "Yes", "No") ifelse(a == 1 && b == 1, "Yes", "No")
squfc = function(xsqu,ysqu){
if( xsqu <= 0 || ysqu <= 0|| is.na(xsqu) || is.na( ysqu) || is.character(xsqu) ||is.character(ysqu)){
print(NA)
}else{
squmatem = xsqu * ysqu
return(squmatem)
}
}
> squfc( 3, 4)
> squfc( 0, 4)
> squfc( 3, 0)
> squfc( 3, NA)
> squfc( NA, 4)
> squfc( 3, "Hi")
> squfc( "Hi", 4)
>
> ww = c(1,NA,3,4,5)
> qq = c(6,7,NA,9,10)
> squfc(ww,qq)
R functions for data type conversion and logical operations
R functions for data type conversion and logical operations
R functions for data type conversion and logical operations

More Related Content

Similar to R functions for data type conversion and logical operations

«PyWat. А хорошо ли вы знаете Python?» Александр Швец, Marilyn System
«PyWat. А хорошо ли вы знаете Python?» Александр Швец, Marilyn System«PyWat. А хорошо ли вы знаете Python?» Александр Швец, Marilyn System
«PyWat. А хорошо ли вы знаете Python?» Александр Швец, Marilyn Systemit-people
 
Useful javascript
Useful javascriptUseful javascript
Useful javascriptLei Kang
 
Parse Everything With Elixir
Parse Everything With ElixirParse Everything With Elixir
Parse Everything With ElixirGabriele Lana
 
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~Atsushi Torikoshi
 
An introduction to property-based testing
An introduction to property-based testingAn introduction to property-based testing
An introduction to property-based testingVincent Pradeilles
 
An example of R code for Data visualization
An example of R code for Data visualizationAn example of R code for Data visualization
An example of R code for Data visualizationLiang (Leon) Zhou
 
Recurrent Networks and LSTM deep dive
Recurrent Networks and LSTM deep diveRecurrent Networks and LSTM deep dive
Recurrent Networks and LSTM deep diveAlex Kalinin
 
Ecuaciones dispositivos electronicos
Ecuaciones dispositivos electronicosEcuaciones dispositivos electronicos
Ecuaciones dispositivos electronicosfsdewr
 
Monadologie
MonadologieMonadologie
Monadologieleague
 
轻量级文本工具集
轻量级文本工具集轻量级文本工具集
轻量级文本工具集March Liu
 
A Course in Fuzzy Systems and Control Matlab Chapter Three
A Course in Fuzzy Systems and Control Matlab Chapter ThreeA Course in Fuzzy Systems and Control Matlab Chapter Three
A Course in Fuzzy Systems and Control Matlab Chapter ThreeChung Hua Universit
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?Tomasz Wrobel
 
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"PromptWorks
 
SparkSQLの構文解析
SparkSQLの構文解析SparkSQLの構文解析
SparkSQLの構文解析ゆり 井上
 
Diapositiva de Estudio: SolPrac2Am4.pptx
Diapositiva de Estudio:  SolPrac2Am4.pptxDiapositiva de Estudio:  SolPrac2Am4.pptx
Diapositiva de Estudio: SolPrac2Am4.pptxjorgejvc777
 

Similar to R functions for data type conversion and logical operations (20)

«PyWat. А хорошо ли вы знаете Python?» Александр Швец, Marilyn System
«PyWat. А хорошо ли вы знаете Python?» Александр Швец, Marilyn System«PyWat. А хорошо ли вы знаете Python?» Александр Швец, Marilyn System
«PyWat. А хорошо ли вы знаете Python?» Александр Швец, Marilyn System
 
Next Level Testing
Next Level TestingNext Level Testing
Next Level Testing
 
Scala Parallel Collections
Scala Parallel CollectionsScala Parallel Collections
Scala Parallel Collections
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
 
Chap 3php array part4
Chap 3php array part4Chap 3php array part4
Chap 3php array part4
 
Parse Everything With Elixir
Parse Everything With ElixirParse Everything With Elixir
Parse Everything With Elixir
 
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~
 
An introduction to property-based testing
An introduction to property-based testingAn introduction to property-based testing
An introduction to property-based testing
 
An example of R code for Data visualization
An example of R code for Data visualizationAn example of R code for Data visualization
An example of R code for Data visualization
 
Recurrent Networks and LSTM deep dive
Recurrent Networks and LSTM deep diveRecurrent Networks and LSTM deep dive
Recurrent Networks and LSTM deep dive
 
Ecuaciones dispositivos electronicos
Ecuaciones dispositivos electronicosEcuaciones dispositivos electronicos
Ecuaciones dispositivos electronicos
 
Monadologie
MonadologieMonadologie
Monadologie
 
轻量级文本工具集
轻量级文本工具集轻量级文本工具集
轻量级文本工具集
 
Meet scala
Meet scalaMeet scala
Meet scala
 
A Course in Fuzzy Systems and Control Matlab Chapter Three
A Course in Fuzzy Systems and Control Matlab Chapter ThreeA Course in Fuzzy Systems and Control Matlab Chapter Three
A Course in Fuzzy Systems and Control Matlab Chapter Three
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
 
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
 
Python Lecture 11
Python Lecture 11Python Lecture 11
Python Lecture 11
 
SparkSQLの構文解析
SparkSQLの構文解析SparkSQLの構文解析
SparkSQLの構文解析
 
Diapositiva de Estudio: SolPrac2Am4.pptx
Diapositiva de Estudio:  SolPrac2Am4.pptxDiapositiva de Estudio:  SolPrac2Am4.pptx
Diapositiva de Estudio: SolPrac2Am4.pptx
 

Recently uploaded

꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Callshivangimorya083
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingNeil Barnes
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxJohnnyPlasten
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxolyaivanovalion
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxolyaivanovalion
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Delhi Call girls
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxolyaivanovalion
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusTimothy Spann
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSAishani27
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxolyaivanovalion
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxolyaivanovalion
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...Suhani Kapoor
 

Recently uploaded (20)

꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data Storytelling
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptx
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptx
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptx
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptx
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICS
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptx
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
 
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
 

R functions for data type conversion and logical operations

  • 1.
  • 2. Kan, Hao-Cheng Lunghwa University of Science and Technology http://kanchengzxdfgcv.blogspot.tw/
  • 3.
  • 4.
  • 5.
  • 6. > as.numeric(TRUE) > as.numeric(FALSE) > as.character(TRUE) > as.character(FALSE) > as.factor(TRUE) > as.factor(FALSE) > > k = "kan" > class(k) > as.character(k) > > n = 123 > class(n) > as.numeric(n) > > test = as.numeric(k) > test
  • 7. > 1 == 1 > 1 < 1 > 1 <= 1 > 1 > 1 > 1 >= 1 > 1 != 1 > toCheck = 1 if (toCheck == 1) { print("hello") } if (toCheck == 0) { print("hello") }
  • 8. check.bool = function(x){ if (x == 1){ print("hello") }else{ print("goodbye") } } > check.bool(1) > check.bool(0) > check.bool("k") > check.bool(TRUE)
  • 9. check.bool = function(x){ if (x == 1){ print("hello") } else if (x == 0){ print("goodbye") } else{ print("confused") } } > check.bool(1) > check.bool(0) > check.bool(2) > check.bool("k")
  • 10.
  • 11. use.switch = function(x){ switch(x, "a"="first", "b"="second", "z"="last", "c"="third", "other") } > use.switch("a") > use.switch("b") > use.switch("c") > use.switch("d") > use.switch("OwO") > use.switch("z") > use.switch(1) > use.switch(2) > use.switch(3) > use.switch(4) > use.switch(5) > use.switch(6) > is.null(use.switch(6))
  • 12.
  • 13. > ifelse(1 == 1, "Yes", "No") > ifelse(1 == 0, "Yes", "No") > > toTest = c(1, 1, 0, 1, 0, 1) > class(toTest) > toTest > > ifelse(toTest == 1, "Yes", "No") > ifelse(toTest == 1, toTest * 3, toTest) > ifelse(toTest == 1, toTest * 3, "Zero") > > toTest[2] = NA > class(toTest) > toTest > > ifelse(toTest == 1, "Yes", "No") > ifelse(toTest == 1, toTest * 3, toTest) > ifelse(toTest == 1, toTest * 3, "Zero")
  • 14.
  • 15. > a = c(1, 1, 0, 1) > b = c(2, 1, 0, 1) > bs = c(2, 1, 0, 1) > > ifelse(a == 1 & b == 1, "Yes", "No") > ifelse(a == 1 && b == 1, "Yes", "No") > ifelse(a == 1 && bs == 1, "Yes", "No") ifelse(a == 1 & b == 1, "Yes", "No") ifelse(a == 1 && b == 1, "Yes", "No")
  • 16.
  • 17.
  • 18. squfc = function(xsqu,ysqu){ if( xsqu <= 0 || ysqu <= 0|| is.na(xsqu) || is.na( ysqu) || is.character(xsqu) ||is.character(ysqu)){ print(NA) }else{ squmatem = xsqu * ysqu return(squmatem) } }
  • 19. > squfc( 3, 4) > squfc( 0, 4) > squfc( 3, 0) > squfc( 3, NA) > squfc( NA, 4) > squfc( 3, "Hi") > squfc( "Hi", 4) > > ww = c(1,NA,3,4,5) > qq = c(6,7,NA,9,10) > squfc(ww,qq)