2016年3月23日

数据文件读写

摘要: R语言数据储存与读取 1 首先用getwd() 获得当前目录,用setwd("C:/data")设定当前目录 2 数据保存 创建数据框d 2.1 保存为简单文本 2.2 保存为逗号分割文本 2.3 保存为R格式文件 2.4 保存工作空间镜像 3 数据读取 读取函数主要有:read.table( ), 阅读全文

posted @ 2016-03-23 14:51 MartinChau 阅读(200) 评论(0) 推荐(0) 编辑

数据类型转换

摘要: test for data type is.numeric() is.character() is.vector() is.matrix() is.data.frame() convert it as.numeric() as.character() as.vector() as.matrix() 阅读全文

posted @ 2016-03-23 14:49 MartinChau 阅读(127) 评论(0) 推荐(0) 编辑

常用基础知识

摘要: 举例 Examples Loops The most commonly used loop structures in R are for, while and apply loops. Less common are repeat loops. The break function is used 阅读全文

posted @ 2016-03-23 14:47 MartinChau 阅读(133) 评论(0) 推荐(0) 编辑

算术运算和逻辑运算

摘要: Arithmetic Operators Operator Description + addition - subtraction * multiplication / division ^ or ** exponentiation x %% y modulus (x mod y) 5%%2 is 1 x %/% y integer division 5%/... 阅读全文

posted @ 2016-03-23 14:42 MartinChau 阅读(289) 评论(0) 推荐(0) 编辑

记录程序运行的时间

摘要: f <- function(start_time) { start_time <- as.POSIXct(start_time) dt <- difftime(Sys.time(), start_time, units="secs") # Since you only want the H:M:S, we can ignore the date... # but you have... 阅读全文

posted @ 2016-03-23 14:40 MartinChau 阅读(147) 评论(0) 推荐(0) 编辑

数据框排序 data.frame order

摘要: # sorting examples using the mtcars dataset attach(mtcars) # sort by mpg newdata <- mtcars[order(mpg),] # sort by mpg and cyl newdata <- mtcars[order(mpg, cyl),] #sort by mpg (ascending) and cyl (... 阅读全文

posted @ 2016-03-23 14:38 MartinChau 阅读(211) 评论(0) 推荐(0) 编辑

合并data.frame (merge)

摘要: Merging Data Adding Columns To merge two data frames (datasets) horizontally, use the merge function. In most cases, you join two data frames by one o 阅读全文

posted @ 2016-03-23 14:37 MartinChau 阅读(538) 评论(0) 推荐(0) 编辑

命令行运行R语言脚本(代码)

摘要: 1 Windows: 键入 cd C:\Program Files\R\R-3.2.0\bin 工作目录切换到R的核心程序目录键入 R BATCH F:\Test.R 或 Rscript F:\Test.R 运行脚本前者R控制台内容记录到Test.Rout文件中,后者则将数据输出到windows控制 阅读全文

posted @ 2016-03-23 14:32 MartinChau 阅读(683) 评论(0) 推荐(0) 编辑

R语言画图基础参数设置

摘要: Graphical Parameters You can customize many features of your graphs (fonts, colors, axes, titles) through graphic options. One way is to specify these 阅读全文

posted @ 2016-03-23 14:30 MartinChau 阅读(3756) 评论(0) 推荐(0) 编辑

日期时间函数

摘要: Sys.Date( ) #returns today's date. date() #returns the current date and time. # print today's date today <-Sys.Date() format(today, format="%B %d %Y") "June 20 2007" # convert date info in format '... 阅读全文

posted @ 2016-03-23 14:25 MartinChau 阅读(280) 评论(0) 推荐(0) 编辑

导航