在R中写入二进制文件
我被要求将 R 输出写入两个二进制文件,一个索引文件和一个主数据文件。索引文件中的每个id都会对应一个矩阵/块。我在互联网上读到过有关在 R 中编写二进制文件的信息,但我不确定如何指定格式以便我可以实现这种格式?
另外,我们可以在 R 中指定短整数吗?他说他希望数字是短整数(两个字节),但我不知道这意味着什么。
我很感激任何意见!谢谢
I am asked to write R output in two binary files, an index file and a main data file. There will be one matrix/block corresponding to each id in the index file. I have read about writing binary files in R on the internet but I am not sure how to specify the format so that I can achieve this format?
Also, can we specify short integer in R? He said he wants the numebers to be short intergets (two bytes) and I don't want what that means.
I appreciate any input! Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于你没有把问题说得很清楚,所以我在下面的示例代码中做了一些假设。给定一个矩阵列表,它将它们保存到
.bin
文件中,并创建一个带有偏移量的.idx
文件。然后,您可以根据给定的索引再次将它们加载回来。未使用您提到的 2 字节大小 - 它将矩阵数据保存为 8 字节双精度数或 4 字节整数(但您可以更改它)。它的使用方法如下:
...以下是其功能:
Since you didn't specify the problem very clearly, I made some assumptions in the sample code below. Given a list of matrices, it saves them to a
.bin
file and creates an.idx
file with offsets. You can then load them back in again given an index. The 2-byte size you mentioned isn't used - it saves the matrix data as 8-byte doubles or 4-byte integers (but you could change that).Here's how it's used:
...and here are the functions:
请参阅help(writeBin),size = 2 定义对每个元素的分配(即两个字节整数)。但如果您不知道这意味着什么,您可能需要请求者提供更多信息。
See help(writeBin), size = 2 defines the allocation to each element (i.e. a two byte integer). But if you don't know what this means you probably will need a lot more information from your requester.