前面添加个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. Oozie工作流属性配置的方式与策略

    本文原文出处: http://blog.csdn.net/bluishglc/article/details/46049817 Oozie工作流属性配置的三种方式 Oozie有三种方法可以给工作流提供 ...

  2. 【转】在 XAML 的属性中,转义大括号 {}

    我们知道大括号"{}"在XAML中是用来处理标记扩展的. 比如: <Button Content="{Binding}"/>   但如何转义而表示普 ...

  3. 关于 隐藏元素(样式为 display: none 的元素)及其子元素 获取不到高度的问题

    IE 和 Edge 中都是这样,Chrome中好像还好. 方法就是换一个样式,还有一个控制显示隐藏的:visibility 相关文档:http://www.w3school.com.cn/cssref ...

  4. [Unity3D]Unity3D游戏开发之跑酷游戏项目解说

    大家好,我是秦元培.我參加了CSDN2014博客之星的评选,欢迎大家为我投票,同一时候希望在新的一年里大家能继续支持我的博客. 大家晚上好.我是秦元培,欢迎大家关注我的博客,我的博客地址是blog.c ...

  5. android笔记--加载框

    package com.fuda.ui; import android.app.Activity; import android.os.Bundle; import android.os.Handle ...

  6. 玩转Bootstrap(JS插件篇)-第1章 模态弹出框 :1-2 动画过渡

    动画过渡(Transitions) 这一小节我们先来讲“动画过渡(Transitions)”这个插件的使用,源文件:transition.js Bootstrap框架默认给各个组件提供了基本动画的过渡 ...

  7. 事件驱动模型的简单Java实现

    事件驱动模型的原理不再赘述,Swing是不错的实现.别人也有不错的博文来说明原理. 本文的目的是提供一种简单的,可供参考的简短代码,用来帮助理解该模型. Project Navigator Event ...

  8. chrome访问不了go语言中文网

    最近开发转用golang语言,所以经常在晚上搜资料,结果发现go语言中文网,我居然访问不了,刚开始以为是跟go有关,所以被防火长城屏蔽了,结果,偶尔讨论发现办公室的其他两个同事都可以访问,真是奇了怪了 ...

  9. jquery实现全选/反选功能

    <!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content=& ...

  10. js的深入学习课程Object.prototype.toString.call()

    1.通过 Object.prototype.toString.call() 进行类型判断 function isArray(obj) { return Object.prototype.toStrin ...