• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

R语言从基础入门到提高(一)Intro to basics(基础介绍)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

其实之前我学习R语言,很是迷茫,不知道从何下手,想找一些视频,但是网上的视频不只少的可怜,而且还收费,对于开源的R来说就显得那么的悲剧啦,然后我想还是找一些书看一下吧,也不知道买什么书,还害怕买完后,不愿意看,然后就是PDF,找了一些PDF的书,单数吸收的没这么好,感觉都跨度挺大的,没有从基础语法讲起,即使讲了,也没那么清晰。

在一次查找ggplot 函数帮助时,发现Rstudio help 里居然有 learning R  在线的学习网站,抱着试试看的态度,就点进去看了看,然后感觉还是国外的有些良心网站,真正做到开源,free,所有的学习资源,都是free的。

这个网站是英文的,但是感觉单词都是很常见的英文词汇,不是问题,除非遇到是在不懂得词汇时,可是用一些翻译词典,本人用的是hai词。

好了下面就把这个网站贴出来

https://www.datacamp.com/home 

这个网站是交互式的,有在线编译器

然后就是我的学习笔记啦,里面有我的心得体会,包括全部运行代码,运行结果,注释等。

如果你不愿意,在线学习,可以跟着我的笔记学习,这样就省了,查单词,翻译,运行,琐事啦,但是本人强烈建议大家,一步步扎实的跟着网站,在线学习一下!!!

 

####(中没有意识到!!!

突然意识到一个问题,解读代码:

先是可能是一段介绍,有的简单的就没有介绍,然后就是贴出来的代码

代码包括:console为分界线,console之前为源代码(含注释),console为 运行结果

####

 

 

# An addition
5 + 5 

# A subtraction
5 - 5 

# A multiplication
3 * 5

 # A division
(5 + 5) / 2 

# Exponentiation
2 ^ 5

# Modulo
28 %% 6

console:
> # An addition
> 5 + 5 
[1] 10
> 
> # A subtraction
> 5 - 5 
[1] 0
> 
> # A multiplication
> 3 * 5
[1] 15
> 
>  # A division
> (5 + 5) / 2 
[1] 5
> 
> # Exponentiation
> 2 ^ 5
[1] 32
> 
> # Modulo
> 28 %% 6
[1] 4
# Assign the value 42 to x
x <- 42

# Print out the value of the variable x
x
console:
> # Assign the value 42 to x
> x <- 42
> 
> # Print out the value of the variable x
> x
[1] 42
# Assign the value 5 to the variable my_apples
my_apples <- 5

# Print out the value of the variable my_apples
my_apples

console:
> # Assign the value 5 to the variable my_apples
> my_apples <- 5
>
> # Print out the value of the variable my_apples
> my_apples
[1] 5
>  
# Assign a value to the variables my_apples and my_oranges
my_apples <- 5
my_oranges <-6

# Add these two variables together
my_apples + my_oranges

# Create the variable my_fruit
my_fruit <- my_oranges+my_apples
console:
> # Assign a value to the variables my_apples and my_oranges
> my_apples <- 5
> my_oranges <-6
> 
> # Add these two variables together
> my_apples + my_oranges
[1] 11
> 
> # Create the variable my_fruit
> my_fruit <- my_oranges+my_apples
>
改错练习:
 # Assign a value to the variable my_apples
my_apples <- 5 

# Fix the assignment of my_oranges
my_oranges <- "six" 

# Create the variable my_fruit and print it out
my_fruit <- my_apples + my_oranges 
my_fruit

console:
> # Assign a value to the variable my_apples
> my_apples <- 5 
> 
> # Fix the assignment of my_oranges
> my_oranges <- "six" 
> 
> # Create the variable my_fruit and print it out
> my_fruit <- my_apples + my_oranges 
Error: non-numeric argument to binary operator
> my_fruit
Error: object \'my_fruit\' not found


提示:
Click \'Submit Answer\' and read the error message. Make sure to understand why this did not work.
Adjust the code so that R knows you have 6 oranges and thus a fruit basket with 11 pieces of fruit.
 Take Hint (-30xp)
Incorrect submission
Your code contains an error that you should fix:
Error: non-numeric argument to binary operator
You can do this by setting the my_oranges variable to a numeric value, not a string!
How helpful is this feedback?


然后 把six 改为6 就可以啦  不贴了!
基本数据类型:
Basic data types in R
100xp
R works with numerous data types. Some of the most basic types to get started are:
Decimals(小数,十进制数) values like 4.5 are called numerics.
Natural numbers like 4 are called integers. Integers(整数) are also numerics.
Boolean(布尔) values (TRUE or FALSE) are called logical.(逻辑数)
Text (or string(字符串)) values are called characters.(对象)
Note how the quotation(引用) marks on the right indicate that "some text" is a character.


# Change my_numeric to be 42
my_numeric <- 42

# Change my_character to be "universe"
my_character <- "universe"

# Change my_logical to be FALSE
my_logical <- FALSE


console:
> # Change my_numeric to be 42
> my_numeric <- 42
> 
> # Change my_character to be "universe"
> my_character <- "universe"
> 
> # Change my_logical to be FALSE
> my_logical <- FALSE

 

"数据"类型 检查 cheak
Do you remember that when you added 5 + "six", you got an error due to a mismatch in data types? You can avoid such embarrassing situations by checking the data type of a variable beforehand. You can do this with the class()function, as the code on the right shows.


# Declare variables of different types
my_numeric <- 42
my_character <- "universe"
my_logical <- FALSE 

# Check class of my_numeric
class(my_numeric)

# Check class of my_character
class(my_character)

# Check class of my_logical
class(my_logical)

console:

> # Declare variables of different types
> my_numeric <- 42
> my_character <- "universe"
> my_logical <- FALSE 
> 
> # Check class of my_numeric
> class(my_numeric)
[1] "numeric"      小数&整数
> 
> # Check class of my_character
> class(my_character)
[1] "character"       字符串
> 
> # Check class of my_logical
> class(my_logical)
[1] "logical"      布尔
>





说实话本人挺喜欢这个的,哈哈,终于找到入门神器啦~

 


 

ps:一切内容均是本人总结提炼的,方式有网上查阅,翻阅书籍。如果设计版权希望能及时提醒更改。同时希望注重保护他人成果!

 


 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap