Rlang(1)Introduction and Installation - Calculate and Load Data

本文介绍了使用R语言进行数据处理、绘图和编程的基础知识,包括安装R环境、基本计算、函数应用、数据管理、文件读取与分析等,并通过实例展示了如何使用R进行数据计算、创建图表和执行简单编程任务。
Rlang(1)Introduction and Installation - Calculate and Load Data

Install R Script
Download the file from here http://www.go-parts.com/mirrors-usa/cran/, I get the version R-3.2.2.pkg.

Install Pandoc - Tool to Convert md to Documents
Download the latest package from here https://github.com/jgm/pandoc/releases/tag/1.15.0.6, I get the version pandoc-1.15.0.6-osx.pkg

Follow the docs here http://dapengde.com/r4dummies

1. Introduction
We use R language to do data process, draw diagram and programming.

Anyone can R - anyone can Er/2, haha.

I already install R-3.2.2.pkg, Need I install https://www.rstudio.com/products/rstudio/download/, RStudio, it is a nice tool.

After I install R-3.2.2.pkg, I can verify the version using following command.
> r --version
R version 3.2.2 (2015-08-14) -- "Fire Safety"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.4.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see

2. Use R to do Calculation
Create a new R script file on Rsutdio, it will create a file named similar to Calculate.R, end with .R.

3 * (2 + 2)
sqrt(9)
## comments here.

Some other useful functions, round(), trunc(), sort(), abs(), exp(), log(), log10(), sin(), cos(), tan(), sin(), cos(), tan().

pi
## 3.141593

> options(digits=22)
> pi
[1] 3.141592653589793115998

> options(digits = 3)
> x <- c(61, 45, 55, 46, 56, 79, 86, 57, 56, 56, 57, 71)
> x[4]
[1] 46

Operation on x
> x + 100
[1] 161 145 155 146 156 179 186 157 156 156 157 171

These commands will directly draw the diagram for us.
options(digits = 3)
x <- c(61, 45, 55, 46, 56, 79, 86, 57, 56, 56, 57, 71)
x[4]
x + 100
plot(x)

## calculate the average
sum(x)/length(x)
mean(x)

Some other useful functions provided by R language, sum(), mean(), max(), min(), range(), median(), sd(), var().

3. Manage the Data from File
Reading the document from here http://dapengde.com/archives/14818, Download the sample data file from here
http://dapengde.com/wp-content/uploads/2013/03/dapengde_DummyR_PM25.csv

Put this in the command console, you will see the help information for read.table
>?read.table

This will read the file directly and open the file with default application
mydata <- "/opt/data/dapengde_DummyR_PM25.csv"
mydata
file.show(mydata)

load the csv data directly from file
mydata <- "/opt/data/dapengde_DummyR_PM25.csv"
mydata
##file.show(mydata)

#pm <- read.table(file=mydata, header = TRUE, sep=",")
pm <- read.csv(file=mydata)

The command summary will display a very useful information about the data
> summary(pm)
time h8 h100 h325
Min. : 0.00 Min. : 46.0 Min. : 32.0 Min. : 30.0
1st Qu.: 5.75 1st Qu.: 75.5 1st Qu.: 48.0 1st Qu.: 42.8
Median :11.50 Median : 93.5 Median : 67.5 Median : 54.5
Mean :11.50 Mean : 98.7 Mean : 72.1 Mean : 65.5
3rd Qu.:17.25 3rd Qu.:128.0 3rd Qu.:100.0 3rd Qu.: 88.5
Max. :23.00 Max. :150.0 Max. :123.0 Max. :126.0

1st Qu and 3rd Qu
https://zh.wikipedia.org/wiki/%E5%9B%9B%E5%88%86%E4%BD%8D%E6%95%B0

Get the row 10, column 2 data.
> pm[10, 2]
[1] 150

Pick up the C array of data with column 2
> pm[c(0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22), 2]
[1] 80 91 100 144 150 106 68 46 68 92 108

Generate the seq from seq()
> pm[seq(0,22,2),2]
[1] 80 91 100 144 150 106 68 46 68 92 108

All data belong to column 2
> pm[,2]
[1] 97 80 64 91 87 100 128 144 150 150 150 106 78 68 62 46 55 68 84 92 95
[22] 108 128 138

Pick up the column H8
> pm[, "h8"]
[1] 97 80 64 91 87 100 128 144 150 150 150 106 78 68 62 46 55 68 84 92 95
[22] 108 128 138

Similar to the command above
> pm$h8
[1] 97 80 64 91 87 100 128 144 150 150 150 106 78 68 62 46 55 68 84 92 95
[22] 108 128 138

List the Column Name
> names(pm)
[1] "time" "h8" "h100" "h325"

References:
http://www.go-parts.com/mirrors-usa/cran/
https://www.r-project.org/
http://www.biosino.org/R/R-doc/files/R4beg_cn_2.0.pdf
https://github.com/yihui/r-ninja
http://pandoc.org/

http://dapengde.com/r4dummies
http://dapengde.com/archives/14802
ERROR: cannot remove earlier installation, is it in use? * removing 'C:/RRR/rlang' * restoring previous 'C:/RRR/rlang' Warning in file.copy(lp, dirname(pkgdir), recursive = TRUE, copy.date = TRUE) : problem copying C:\RRR\00LOCK-rlang\rlang\libs\x64\rlang.dll to C:\RRR\rlang\libs\x64\rlang.dll: Permission denied Warning in install.packages : installation of package ‘rlang’ had non-zero exit status * installing *source* package 'vctrs' ... ** package 'vctrs' successfully unpacked and MD5 sums checked ERROR: cannot remove earlier installation, is it in use? * removing 'C:/RRR/vctrs' * restoring previous 'C:/RRR/vctrs' Warning in file.copy(lp, dirname(pkgdir), recursive = TRUE, copy.date = TRUE) : problem copying C:\RRR\00LOCK-vctrs\vctrs\libs\x64\vctrs.dll to C:\RRR\vctrs\libs\x64\vctrs.dll: Permission denied Warning in install.packages : installation of package ‘vctrs’ had non-zero exit status * installing *source* package 'dbplyr' ... ** package 'dbplyr' successfully unpacked and MD5 sums checked ** using staged installation ** R ** inst ** byte-compile and prepare package for lazy loading Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : namespace 'rlang' 1.1.0 is being loaded, but >= 1.1.1 is required Calls: <Anonymous> ... withCallingHandlers -> loadNamespace -> namespaceImport -> loadNamespace Execution halted ERROR: lazy loading failed for package 'dbplyr' * removing 'C:/RRR/dbplyr' Warning in install.packages : installation of package ‘dbplyr’ had non-zero exit status The downloaded source packages are in ‘C:\系统缓存\RtmpMrOhpA\downloaded_packages’
06-07
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值