前面添加个lapply()或者dplyr::llply()就能读取,储存多个文件了。
http://bluemountaincapital.github.io/FSharpRProvider/reading-rdata.html

Reading and writing RData files

When using R, you can save and load data sets as *.rdata files. These can be easily exported and consumed using the R provider too, so if you want to perform part of your data acquisition, analysis and visualization using F# and another part using R, you can easily pass the data between F# and R as *.rdata files.

Passing data from R to F#

Let's say that you have some data in R and want to pass them to F#. To do that, you can use the save function in R. The following R snippet creates a simple *.rdata file containing a couple of symbols from the sample volcano data set:

1:
2:
3:
4:
5:
require(datasets)
volcanoList <- unlist(as.list(volcano))
volcanoMean <- mean(volcanoList)
symbols <- c("volcano", "volcanoList", "volcanoMean")
save(list=symols, file="C:/data/sample.rdata")

To import the data on the F# side, you can use the RData type provider that is available in the RProvider namespace. It takes a static parameter specifying the path of the file (absolute or relative) and generates a type that exposes all the saved values as static members:

1:
2:
3:
4:
5:
6:
7:
8:
9:
open RProvider

type Sample = RData<"data/sample.rdata">
let sample = Sample() // Easily access saved values
sample.volcano
sample.volcanoList
sample.volcanoMean

When accessed, the type provider automatically converts the data from the R format to F# format. In the above example,volcanoList is imported as float[] and the volcanoMean value is a singleton array. (The provider does not detect that this is a singleton, so you can get the value using sample.volcanoMean.[0]). For the sample.volcano value, the R provider does not have a default conversion and so it is exposed as SymbolicExpression.

When you have a number of *.rdata files containing data in the same format, you can pick one of them as a sample (which will be used to determine the fields of the type) and then pass the file name to the constructor of the generated type to load it. For example, if we had files data/sample_1.rdata to data/sample_10.rdata, we could read them as:

1:
2:
3:
4:
let means =
[ for i in 1 .. 10 ->
let data = Sample(sprintf "data/sample_%d.rdata" i)
data.volcanoMean.[0] ]

Note that the default conversions available depend on the plugins that are currently available. For example, when you install the enrie FsLab package with the Deedle library, the RData provider will automatically expose data frames as DeedleFrame<string, string> values.

Passing data from F# to R

If you perform data acquisition in F# and then want to pass the data to R, you can use the standard R functions for saving the*.rdata files. The easiest option is to call the R.assign function to define named values in the R environment and then useR.save to save the environment to a file:

1:
2:
3:
4:
5:
6:
7:
8:
9:
// Calculate sum of square differences
let avg = sample.volcanoList |> Array.average
let sqrs =
sample.volcanoList
|> Array.map (fun v -> pown (v - avg) 2) // Save the squares to an RData file
R.assign("volcanoDiffs", sqrs)
R.save(list=[ "volcanoDiffs" ], file="C:/temp/volcano.rdata")

It is recommended to use the list parameter of the save function to specify the names of the symbols that should be saved, rather than saving all symbols. The R provider uses additional temporary symbols and so the saved file would otherwise contain unnecessary fileds.

Once you save the file using the above command, you can re-load it again using the RData type provider, such as: new RData<"C:/temp/volcano.rdata">().

Reading and writing RData files的更多相关文章

  1. Reading and Writing CSV Files in C#

    Introduction A common requirement is to have applications share data with other programs. Although t ...

  2. Writing Text Files On The Client in Oracle Forms 10g

    Below is the example to write file on client in Oracle Forms 10g with webutil library package.Note:  ...

  3. PostgreSQL Reading Ad Writing Files、Execution System Instructions Vul

    catalog . postgresql简介 . 文件读取/写入 . 命令执行 . 影响范围 . 恶意代码分析 . 缓解方案 1. postgresql简介 PostgreSQL 是一个自由的对象-关 ...

  4. Reading or Writing to Another Processes Memory in C# z

    http://www.jarloo.com/reading-and-writing-to-memory/ Declarations [Flags] public enum ProcessAccessF ...

  5. Apache POI – Reading and Writing Excel file in Java

    来源于:https://www.mkyong.com/java/apache-poi-reading-and-writing-excel-file-in-java/ In this article, ...

  6. Reading and writing

    A text file is a sequence of characters stored on a permanent medium like a hard drive, flash memory ...

  7. Analysis about different methods for reading and writing file in Java language

    referee:Java Programming Tutorial Advanced Input & Output (I/O) JDK 1.4+ introduced the so-calle ...

  8. DotNet 资源大全中文版(Awesome最新版)

    Awesome系列的.Net资源整理.awesome-dotnet是由quozd发起和维护.内容包括:编译器.压缩.应用框架.应用模板.加密.数据库.反编译.IDE.日志.风格指南等. 算法与数据结构 ...

  9. Thinking in Java——笔记(18)

    I/O The original byte-oriented library was supplemented with char-oriented, Unicode-based I/O classe ...

随机推荐

  1. iframe调用父页面函数用法举例

    iframe如何调用父页面函数. window.parent.xxxxx();//xxxxx()代表父页面方法具体列子如下,其中包括easyUI的右键和单击事件parent.jspbody部分代码 & ...

  2. [svc]nginx优化

    nginx的25条优化

  3. Linux下找不到so文件的解决办法

    http://www.cnblogs.com/xudong-bupt/p/3698294.html 如果使用自己手动生成的动态链接库.so文件,但是这个.so文件,没有加入库文件搜索路劲中,程序运行时 ...

  4. 详细介绍Base64的编码转换方式

    下面,详细介绍Base64的编码转换方式. 所谓Base64,就是说选出64个字符----小写字母a-z.大写字母A-Z.数字0-9.符号"+"."/"(再加上 ...

  5. ossec变更alert等级及配置邮件预警

    一.场景 当攻击者尝试使用字典对某一台主机的sshd服务进行暴力破解的时候,如果我们能第一时间受到攻击预警的邮件的话,对安全人员或者运维人员来说都能做出快速响应.而使用ossec恰巧可以完成这一工作, ...

  6. Python Pycharm连接Ubantu Python环境

    由于我习惯在window下开发,但是代码环境布局在Ubantu.使用Python,为了方便程序的调试,尝试在Windows下的Pycharm远程连接到Ubantu虚拟机下的Python环境. 1.准备 ...

  7. 【开发】MFC到Delphi的皮肤移植

       最近一直在学嵌入式,蛋疼啊,专业学软件的去搞硬件原理,真心有点伤不起,比较无聊,希望尽早脱离这个状态. 中午在林同学那里看到他在MFC上应用了Skin++皮肤,这是一款通用的软件换肤套件,支持各 ...

  8. scp拷贝提示its a directory 错误

    scp拷贝提示its a directory 错误 场景 使用scp的格式是 scp my_file user@ip:/home/directory 之前也一直这么用,没什么错误,莫名其妙 原因定位 ...

  9. 【转】关于 SELECT /*!40001 SQL_NO_CACHE */ * FROM 的解惑

    由于 在数据库做了缓存,在对数据库做了备份,然后在慢查询日志中发现了这一串字符: SELECT /*!40001 SQL_NO_CACHE */ * FROM 上网查了一下,发现好多答案,好多人说的都 ...

  10. Python爬取猫眼top100排行榜数据【含多线程】

    # -*- coding: utf-8 -*- import requests from multiprocessing import Pool from requests.exceptions im ...