Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将值重新指定给ffdf[R]中的列_R_Ff_Ffbase - Fatal编程技术网

将值重新指定给ffdf[R]中的列

将值重新指定给ffdf[R]中的列,r,ff,ffbase,R,Ff,Ffbase,在较大的数据集中执行以下操作时遇到问题。我想知道是否有一种内置的方法可以使用ff或ffdf来实现这一点 示例:使用substr修改ffdf对象中的字符列并将其重新指定为其他列: require(ffbase) > iris Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 setosa 2

在较大的数据集中执行以下操作时遇到问题。我想知道是否有一种内置的方法可以使用ff或ffdf来实现这一点

示例:使用substr修改ffdf对象中的字符列并将其重新指定为其他列:

require(ffbase)
> iris
    Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
1            5.1         3.5          1.4         0.2     setosa
2            4.9         3.0          1.4         0.2     setosa
3            4.7         3.2          1.3         0.2     setosa
4            4.6         3.1          1.5         0.2     setosa

#Convert to ff object
A <- as.ffdf(iris)
但是,例如,如果我想对字符1到3进行子串,我会得到以下错误:

> substr(as.character(A$Species),1,3)
Error in substr(as.character(A$Species), 1, 3) : 
  extracting substrings from a non-character object 
修改ffdf对象中的列有哪些准则

编辑

我还尝试了ffdfdply方法。对于一个相当小的数据,似乎需要很长时间:

substrff <- function(x){
  x$new <- substr(x$Species,1,8)
  return(x)
}

B <-  ffdfdply(x=A, split = A$Species, FUN = substrff)
substrff
require(ffbase)
数据(iris,package=“数据集”)

谢谢你!我不知道“with”或“with.ffdf”的功能是否允许对一列执行大多数操作?with.ffdf将以行的形式(受RAM可用性的限制)获取RAM中的数据,接下来您可以对指定的列执行任何向量化操作。
substrff <- function(x){
  x$new <- substr(x$Species,1,8)
  return(x)
}

B <-  ffdfdply(x=A, split = A$Species, FUN = substrff)
require(ffbase)
data(iris, package = "datasets")
x <- as.ffdf(iris)
x$spec <- with(x[c("Species")], substr(Species, 1, 4))