R:部分命令

来源:互联网 发布:php b2b2c开源系统 编辑:程序博客网 时间:2024/06/05 18:51


=====================================================

*** 用于管理工作空间:


getwd() 显示当前的工作目录
setwd("mydirectory") 修改当前的工作目录为mydirectory
ls() 列出当前工作空间中的对象
rm(objectlist) 移除(删除)一个或多个对象
help(options) 显示可用选项的说明
options() 显示或设置当前选项
history(#) 显示最近使用过的#个命令(默认值为25)
savehistory("myfile") 保存命令历史到文件myfile中(默认值为.Rhistory)
loadhistory("myfile") 载入一个命令历史文件(默认值为.Rhistory)
save.image("myfile") 保存工作空间到文件myfile中(默认值为.RData)
save(objectlist, file="myfile") 保存指定对象到一个文件中
load("myfile") 读取一个工作空间到当前会话中(默认值为.RData)
q() 退出R。将会询问你是否保存工作空间


=====================================

*** 包的安装,运行数据集例子


安装 vcd 包:
install.packages()

列出此包中可用的函数和数据集:
help(package="vcd")

载入这个包 vcd:
library(vcd)

阅读数据集 Arthritis 的描述:
help(Arthritis)

显示数据集 Arthritis 的内容:
Arthritis

运行数据集 Arthritis 自带的示例:
example(Arthritis)


=============================================

***调用 ggplot2 包中的 diamonds 数据集


自带diamonds数据的调用:

首先调用包 ggplot2:

library(ggplot2)

就可以使用 diamonds数据集了。


===============================================

*** 制作学生成绩数据集


> name <-  c("John", "Tom")
> point <- c(98, 80)
> studentdata <- data.frame(name, point)
> studentdata
  name point
1 John    98
2  Tom    80