r 将数据输入和输出剪贴板等来自http://rfordummies.com/sample-code/chapter-12-getting-data-into-and-out-of-r/

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了r 将数据输入和输出剪贴板等来自http://rfordummies.com/sample-code/chapter-12-getting-data-into-and-out-of-r/相关的知识,希望对你有一定的参考价值。

 
# Chapter 12
# Getting Data into and out of R
 
# NOTE : Most of the code depends on actions, directories
# and the presence of files. Code that isn't runnable is
# commented out.
 
# Getting Data into R
 
## Entering data in the R text editor
 
elements <- data.frame()
elements <- edit(elements)
 
# print(elements)
 
## Using the Clipboard to copy and paste
 
#### Reminder : This only works on Windows
x <- readClipboard()
x
x <- read.table(file = "clipboard", sep = "\t", header=TRUE)
x
 
## Reading data in CSV files
 
### Using read.csv() to import data
 
elements <- read.csv(file.path("f:", "elements.csv"))
str(elements)
elements <- read.csv(file.path("f:", "elements.csv"), stringsAsFactors=FALSE)
str(elements)
 
### Using read.table() to import tabular data in text files
 
## Reading data from Excel
install.packages("XLConnect")
library("XLConnect")
excel.file <- file.path("~/Elements.xlsx")
 
elements <- readWorksheetFromFile(excel.file, sheet=1)
elements <- readWorksheetFromFile(excel.file, sheet="Sheet1")
 
## Working with other data types
 
library(foreign)
read.spss(file="location/of/myfile")
 
# Getting Your Data out of R
 
 
writeClipboard(names(iris))
 
write.table(head(iris), file="clipboard", sep="\t", row.names=FALSE)
 
# Working with Files and Folders
 
## Understanding the working directory
getwd()
 
setwd("F:/git/roxygen2")
getwd()
setwd("F:\\git\\stringr")
getwd()
 
file.path("f:", "git", "surveyor")
 
setwd(file.path("F:", "git", "roxygen2"))
getwd()
 
file.path("F:", "git", "roxygen2", "roxygen2", "README.md" )
 
## Manipulating files
 
# list.files(file.path("F:", "git", "roxygen2"))
my.file <- tempfile()
my.file
write.csv(iris, file=my.file)
list.files(tempdir())
 
file.iris <- read.csv(my.file)
 
file.remove(my.file)
list.files(tempdir())

以上是关于r 将数据输入和输出剪贴板等来自http://rfordummies.com/sample-code/chapter-12-getting-data-into-and-out-of-r/的主要内容,如果未能解决你的问题,请参考以下文章

求解:怎么将r软件内的数据转换为excel数据?

r 功能:将数据复制到剪贴板以进行Excel

如何在 Pentaho Spoon UI 中输入多行值?

如何将r中的格式化数据表复制到剪贴板

如何将tmux输出复制到系统剪贴板

AS3 如何将数据从对象提取到剪贴板、rest、db、文件等?