本文介绍了如何将ffdf应用于非原子数据帧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多帖子()声称 ff 包优于 bigmemory ,因为它可以处理对象w /原子和非原子分量,但如何?例如:

Many posts (such as this) claim the ff package is superior to bigmemory because it can handle objects w/ atomic and nonatomic components, but how? For example:

UNIT <- c(100,100, 200, 200, 200, 200, 200, 300, 300, 300,300)
STATUS <- c('ACTIVE','INACTIVE','ACTIVE','ACTIVE','INACTIVE','ACTIVE','INACTIVE','ACTIVE',
        'ACTIVE','ACTIVE','INACTIVE') 
TERMINATED <- as.Date(c('1999-07-06','2008-12-05','2000-08-18','2000-08-18','2000-08-18',
                    '2008-08-18','2008-08-18','2006-09-19','2006-09-19','2006-09-19',
                    '1999-03-15')) 
START <- as.Date(c('2007-04-23','2008-12-06','2004-06-01','2007-02-01','2008-04-19',
               '2010-11-29','2010-12-30','2007-10-29','2008-02-05','2008-06-30',
               '2009-02-07'))
STOP <- as.Date(c('2008-12-05','2012-12-31','2007-01-31','2008-04-18','2010-11-28',
              '2010-12-29','2012-12-31','2008-02-04','2008-06-29','2009-02-06',
              '2012-12-31'))
TEST <- data.frame(UNIT,STATUS,TERMINATED,START,STOP)
TEST                   

#install.packages('ff')            
library('ff')            
TEST2 <- ffdf(TEST)            
Error in ffdf(TEST) : ffdf components must be atomic ff objects

做这个工作吗

推荐答案

使用

TEST2 <- as.ffdf(TEST)   

而不是

TEST2 <- ffdf(TEST)   

将工作。

说明:
as.ffdf 将您的data.frame转换为ffdf 。
如果您真的想直接使用 ffdf ,则需要提供原子ff向量,因为错误消息指示。对于上述例子,这将是

Explanation:as.ffdf converts your data.frame to an ffdf.If you really want to use ffdf directly, you need to supply atomic ff vectors as the error message indicates. For the above example this would be

ffdf(UNIT = as.ff(UNIT), STATUS = as.ff(as.factor(STATUS)), TERMINATED = as.ff(TERMINATED), START = as.ff(START), STOP = as.ff(STOP))

请参见as.ffdf或?ffdf,ff包的一部分。

See ?as.ffdf or ?ffdf, part of the ff package.

在现实生活中,您的数据将来自其他来源,如csv或SQL源代码而不是已经在R中的data.frame。请参阅package 将数据从SQL获取到ff。

In real life, your data would be coming from other sources like csv or SQL sources instead of from a data.frame already in R. See package ETLUtils to get your data from SQL into ff easily.

这篇关于如何将ffdf应用于非原子数据帧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 00:54