- 浏览: 2477644 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Rlang(3)Factor - String - Function and Package
1. Factor
Download more sample data from Here
http://dapengde.com/wp-content/uploads/2013/03/dapengde_DummyR_PMBeijing.csv
http://dapengde.com/wp-content/uploads/2013/03/dapengde_DummyR_PMZhengzhou.csv
Load all the data in
bj <- read.csv(file="/opt/data/dapengde_DummyR_PMBeijing.csv")
zz <- read.csv(file="/opt/data/dapengde_DummyR_PMZhengzhou.csv")
Add one more column
bj$city <- "Beijing"
zz$city <- "Zhengzhou"
Combine the 2 collections of data
data <- rbind(bj, zz)
The data format will be
index date pm city
1 1 5 Beijing
...
Not like summary, str() function will provide us some other information
> str(data)
'data.frame': 37 obs. of 3 variables:
$ date: int 1 2 3 4 5 6 7 8 9 10 ...
$ pm : int 5 27 75 22 130 228 220 205 63 35 ...
$ city: chr "Beijing" "Beijing" "Beijing" "Beijing" ...
Factor the column of data:
data$city <- factor(data$city)
Check the summary:
str(data)
How many levels we have
nlevels(data$city)
List all the levels
levels(data$city)
Draw the box diagram
plot(x = data$city, y = data$pm)
Print the average value of different cities
> for( i in levels(data$city)) {
+ print(i)
+ print(mean(data$pm[data$city == i]))
+ }
[1] "Beijing"
[1] 125
[1] "Zhengzhou"
[1] 66.8
The sample logic, less codes
> tapply(data$pm, data$city, mean)
Beijing Zhengzhou
124.7 66.8
2. Master of String
> mydata <- "/opt/data/dapengde_DummyR_PM25.csv"
> mydata
[1] "/opt/data/dapengde_DummyR_PM25.csv"
> class(mydata)
[1] "character"
Connect 2 Things into 1
> paste("hua","luo")
[1] "hua luo"
> paste("hua","luo",sep="_")
[1] "hua_luo"
> paste(c("carl","hua"), "luo")
[1] "carl luo" "hua luo"
We can do paste on collections as well
> paste(c("carl","kiko"), c("luo","kang"))
[1] "carl luo" "kiko kang"
> paste(c("carl","kiko"), c("luo"))
[1] "carl luo" "kiko luo"
> paste(c("carl","kiko"), c("luo","kang","xie"))
[1] "carl luo" "kiko kang" "carl xie"
cat a new line or tab some spaces
> cat("\n","new line", "\n", "new line", "\n", "tab the word","\t","be tabbed")
new line
new line
tab the word be tabbed
count the characters in the string
> x = "luohua"
> nchar(x)
[1] 6
Split the string
> strsplit("luohua","u")
[[1]]
[1] "l" "oh" "a"
substr(), substring()
Search keyword
> grep("java", c("javaworld", "scala based on java", "python is great"))
[1] 1 2
Search and Replace the words
> gsub("java", "scala", c("we build our system using java", "java is the main language we are using"))
[1] "we build our system using scala" "scala is the main language we are using"
> sub("java", "scala", c("we build our system using java", "java is the main language we are using"))
[1] "we build our system using scala" "scala is the main language we are using"
Search and Replace Each Char
> chartr("ja", "sc", c("we build our system using java", "java is the main language we are using"))
[1] "we build our system using scvc" "scvc is the mcin lcngucge we cre using"
Lower case and Upper case
> toupper("carl")
[1] "CARL"
> tolower("CARL")
[1] "carl"
3. Function
Check function sd
> x <- 1:5
> sd(x)
[1] 1.58
> ?sd
> sd
function (x, na.rm = FALSE)
sqrt(var(if (is.vector(x)) x else as.double(x), na.rm = na.rm))
<bytecode: 0x10ca5abf8>
<environment: namespace:stats>
assign function is equal to <-
> assign("x", 1:5)
> x
[1] 1 2 3 4 5
Define the Function Our Selves
> newscore <- function(x) {
+ sqrt(x) * 10
+ }
> newscore(x=40)
[1] 63.2
> newscore2 <- function(x,n) {
+ sqrt(x) * 10 + n
+ }
> newscore2(36,10)
[1] 70
> newscore2
function(x,n) {
sqrt(x) * 10 + n
}
Give function Default Value
> newscore <- function(x=36) {
+ sqrt(x) * 10
+ }
> newscore()
[1] 60
And the last line will be the return value of the function.
4. Packages
Total Seven Thousand packages?
> length(unique(rownames(available.packages())))
[1] 7086
Download and Install the Package directly on the Command Line
> install.packages("maptools")
also installing the dependency ‘sp’
trying URL 'https://cran.rstudio.com/bin/macosx/mavericks/contrib/3.2/sp_1.1-1.tgz'
Content type 'application/x-gzip' length 1508408 bytes (1.4 MB)
==================================================
downloaded 1.4 MB
trying URL 'https://cran.rstudio.com/bin/macosx/mavericks/contrib/3.2/maptools_0.8-36.tgz'
Content type 'application/x-gzip' length 1728083 bytes (1.6 MB)
==================================================
downloaded 1.6 MB
Before I use that package, I need to load that package first, in the original document, it does not mention that at the first example.
> require(maptools)
> position <- c(116.39, 39.91)
> mydate <- "2015-09-02"
> sunriset(matrix(position, nrow = 1), as.POSIXct(mydate, tz = "Asia/Shanghai"),
+ direction = c("sunrise"), POSIXct.out = TRUE)$time
[1] "2015-09-02 05:42:30 CST"
> sunriset(matrix(position, nrow = 1), as.POSIXct(mydate, tz = "Asia/Shanghai"),
+ direction = c("sunset"), POSIXct.out = TRUE)$time
[1] "2015-09-02 18:45:28 CST"
An animation Package
install.packages("animation")
require(animation)
demo("fireworks")
citation("animation")
References:
http://dapengde.com/archives/14845
http://dapengde.com/archives/14858
http://dapengde.com/archives/14862
http://dapengde.com/archives/14905
http://dapengde.com/archives/14850 exercise
1. Factor
Download more sample data from Here
http://dapengde.com/wp-content/uploads/2013/03/dapengde_DummyR_PMBeijing.csv
http://dapengde.com/wp-content/uploads/2013/03/dapengde_DummyR_PMZhengzhou.csv
Load all the data in
bj <- read.csv(file="/opt/data/dapengde_DummyR_PMBeijing.csv")
zz <- read.csv(file="/opt/data/dapengde_DummyR_PMZhengzhou.csv")
Add one more column
bj$city <- "Beijing"
zz$city <- "Zhengzhou"
Combine the 2 collections of data
data <- rbind(bj, zz)
The data format will be
index date pm city
1 1 5 Beijing
...
Not like summary, str() function will provide us some other information
> str(data)
'data.frame': 37 obs. of 3 variables:
$ date: int 1 2 3 4 5 6 7 8 9 10 ...
$ pm : int 5 27 75 22 130 228 220 205 63 35 ...
$ city: chr "Beijing" "Beijing" "Beijing" "Beijing" ...
Factor the column of data:
data$city <- factor(data$city)
Check the summary:
str(data)
How many levels we have
nlevels(data$city)
List all the levels
levels(data$city)
Draw the box diagram
plot(x = data$city, y = data$pm)
Print the average value of different cities
> for( i in levels(data$city)) {
+ print(i)
+ print(mean(data$pm[data$city == i]))
+ }
[1] "Beijing"
[1] 125
[1] "Zhengzhou"
[1] 66.8
The sample logic, less codes
> tapply(data$pm, data$city, mean)
Beijing Zhengzhou
124.7 66.8
2. Master of String
> mydata <- "/opt/data/dapengde_DummyR_PM25.csv"
> mydata
[1] "/opt/data/dapengde_DummyR_PM25.csv"
> class(mydata)
[1] "character"
Connect 2 Things into 1
> paste("hua","luo")
[1] "hua luo"
> paste("hua","luo",sep="_")
[1] "hua_luo"
> paste(c("carl","hua"), "luo")
[1] "carl luo" "hua luo"
We can do paste on collections as well
> paste(c("carl","kiko"), c("luo","kang"))
[1] "carl luo" "kiko kang"
> paste(c("carl","kiko"), c("luo"))
[1] "carl luo" "kiko luo"
> paste(c("carl","kiko"), c("luo","kang","xie"))
[1] "carl luo" "kiko kang" "carl xie"
cat a new line or tab some spaces
> cat("\n","new line", "\n", "new line", "\n", "tab the word","\t","be tabbed")
new line
new line
tab the word be tabbed
count the characters in the string
> x = "luohua"
> nchar(x)
[1] 6
Split the string
> strsplit("luohua","u")
[[1]]
[1] "l" "oh" "a"
substr(), substring()
Search keyword
> grep("java", c("javaworld", "scala based on java", "python is great"))
[1] 1 2
Search and Replace the words
> gsub("java", "scala", c("we build our system using java", "java is the main language we are using"))
[1] "we build our system using scala" "scala is the main language we are using"
> sub("java", "scala", c("we build our system using java", "java is the main language we are using"))
[1] "we build our system using scala" "scala is the main language we are using"
Search and Replace Each Char
> chartr("ja", "sc", c("we build our system using java", "java is the main language we are using"))
[1] "we build our system using scvc" "scvc is the mcin lcngucge we cre using"
Lower case and Upper case
> toupper("carl")
[1] "CARL"
> tolower("CARL")
[1] "carl"
3. Function
Check function sd
> x <- 1:5
> sd(x)
[1] 1.58
> ?sd
> sd
function (x, na.rm = FALSE)
sqrt(var(if (is.vector(x)) x else as.double(x), na.rm = na.rm))
<bytecode: 0x10ca5abf8>
<environment: namespace:stats>
assign function is equal to <-
> assign("x", 1:5)
> x
[1] 1 2 3 4 5
Define the Function Our Selves
> newscore <- function(x) {
+ sqrt(x) * 10
+ }
> newscore(x=40)
[1] 63.2
> newscore2 <- function(x,n) {
+ sqrt(x) * 10 + n
+ }
> newscore2(36,10)
[1] 70
> newscore2
function(x,n) {
sqrt(x) * 10 + n
}
Give function Default Value
> newscore <- function(x=36) {
+ sqrt(x) * 10
+ }
> newscore()
[1] 60
And the last line will be the return value of the function.
4. Packages
Total Seven Thousand packages?
> length(unique(rownames(available.packages())))
[1] 7086
Download and Install the Package directly on the Command Line
> install.packages("maptools")
also installing the dependency ‘sp’
trying URL 'https://cran.rstudio.com/bin/macosx/mavericks/contrib/3.2/sp_1.1-1.tgz'
Content type 'application/x-gzip' length 1508408 bytes (1.4 MB)
==================================================
downloaded 1.4 MB
trying URL 'https://cran.rstudio.com/bin/macosx/mavericks/contrib/3.2/maptools_0.8-36.tgz'
Content type 'application/x-gzip' length 1728083 bytes (1.6 MB)
==================================================
downloaded 1.6 MB
Before I use that package, I need to load that package first, in the original document, it does not mention that at the first example.
> require(maptools)
> position <- c(116.39, 39.91)
> mydate <- "2015-09-02"
> sunriset(matrix(position, nrow = 1), as.POSIXct(mydate, tz = "Asia/Shanghai"),
+ direction = c("sunrise"), POSIXct.out = TRUE)$time
[1] "2015-09-02 05:42:30 CST"
> sunriset(matrix(position, nrow = 1), as.POSIXct(mydate, tz = "Asia/Shanghai"),
+ direction = c("sunset"), POSIXct.out = TRUE)$time
[1] "2015-09-02 18:45:28 CST"
An animation Package
install.packages("animation")
require(animation)
demo("fireworks")
citation("animation")
References:
http://dapengde.com/archives/14845
http://dapengde.com/archives/14858
http://dapengde.com/archives/14862
http://dapengde.com/archives/14905
http://dapengde.com/archives/14850 exercise
发表评论
-
Stop Update Here
2020-04-28 09:00 256I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 422NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 302Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 314Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 287Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 374Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 368Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 318Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 393VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 329Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 408NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 348Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 283Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 202GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 384GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 270GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 255Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 253Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 245Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 230Serverless with NodeJS and Tenc ...
相关推荐
rlang, 面向 R 编程的低层 API rlang 重要的: rlang API仍在成熟。 请参见 ?rlang::lifecycle 以获得被认为是稳定的函数列表。概述rlang软件包提供了使用 R 和tidyverse的核心语言功能的工具:系统
rlang; Python; rpy2 2017-12-21 rlang; 电阻 2018-02-16 新维; linux 2018-02-03 jupyter; 工作室; 笔记本; 系统 2018-03-08 护目镜; 乌本图 2018-03-19 Python; R; 包裹; 备份; 恢复; 点子; conda 2018-03-19...
rlang:使用R进行编程的低级API
Downloading http://pypi.doubanio.com/packages/69/ca/926f7cd3a2014b16870086b2d0fdc84a9e49473c68a8dff8b57f7c156f43/gunicorn-20.0.4-py2.py3-none-any.whl (77kB) |████████████████████...
都是我在画图中需要用到的包,如...2.3.0/maps_3.3.0/maptools_0.9-4/memoise_1.1.0/munsell_0.5.0/pillar_1.3.0/plyr_1.8.4/R6_2.2.2/RCurl_1.95-4.11/rlang_0.3.0.1/scales_1.0.0/sp_1.3-1/tibble_1.4.2/withr_2.1.2
由于R软件版本问题,一些函数不能运用,在此编写了一个程序包可以使那些函数可以用。
R语言迷你教程 编程是一点点学习的。 您建立在基本概念上。 您将已经拥有的知识转移到另一种语言。 午餐休息课程在短期课程中讲授R(一种用于数据分析和报告的最受欢迎的编程语言),以扩展现有程序员已经知道的知识...
三层DLL架构解决方案-示范,值得研究一下
R是用于数据分析的语言,通过Rcpp可以将cpp库引入R中使用,适用于提高性能和接入原有算法库的场合。 Rcpp包提供C++类方便C or C++代码与R软件包进行交互,使用R中提供的.Call() 调用界面。 Rcpp提供R中的基础数据...
Erlang opt_win64 20.2 windows exe 安装包 Erlang 20.2 is the upcoming version of Erlang For Windows x64 installer 截至2018.01.25 groovy最新最稳定版本
A GUIDE TO FUNCTIONAL PROGRAMMING IN E RLANG FOR THE EXPERIENCED PROCEDURAL DEVELOPER.
library( rlang ) 能够对数据帧执行按行操作很有用。 作为一个简单的示例(显然,在实践中,这些列不应该是列表列,但现在忽略它),这将失败: tibble( a = list ( 10 , 11 ), b = list ( 3 , 4 )) % > % mutate...
ÈrlangģenericģAME小号erver + Unity3D 这个项目是一部分 这是一个测试,说明如何将Unity3D连接到鸡蛋,并有一个不错的客户端播放和录制要显示的视频;)这只是为了好玩! 视频: 作者 乔迪·洛朗(Jordi Llonch...
ECG是E rlang函数C的所有图G enerator,其自动绘制函数调用和处理程序派生。 ECG利用Erlang强大的跟踪机制和可视化工具graphviz ,确保已安装graphviz ,并且由于此处使用Python绑定,因此还需要安装Digraph软件包。...
数据分析和可视化的蘸酱 包装dipsaus提供add-ons到各种软件包,如shiny , rlang , future等,以增强这些软件包。 从Github安装开发版本包, devtools :: install_github( ' dipterix/dipsaus ' ) dipsaus从以下...
backbone cordova drools els erlang idea ip jenkins less meteor mis nginx perl php7 postgresql qc rlang sass scrapy selenium shell smarty solr vuw webgl wxpy zookeeper 计算机基础 软工 数据结构 数据挖掘
两个相关系数的比较[p, z, za, zb] = corr_rtest(ra, rb, na, nb) 灵感来自 Rlang 的 r.test() http://personality-project.org/r/html/r.test.html
京东商城API接口,支持多种语言版(Java,C#,Python,Delphi,RLang,GoLang等语言)接口方式,可以通过配置界面直接配置,非常简单,非常直观,1小时可以上手