[英]Reassigning values to columns in ffdf [R]
I am having trouble doing the following operations in a larger dataset. 我无法在较大的数据集中执行以下操作。 I wonder if there is a built in way to do it with either ff or ffdf. 我想知道是否有使用ff或ffdf的内置方法。
Example: Modifying a character columns in an ffdf object using substr and reassign it as a different column: 示例:使用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)
I can access the "Species" column 我可以访问“种类”列
A$species
> A$Species
ff (open) integer length=150 (150) levels: setosa versicolor virginica
[1] [2] [3] [4] [5] [6] [7] [8] [143] [144]
setosa setosa setosa setosa setosa setosa setosa setosa : virginica virginica
[145] [146] [147] [148] [149] [150]
virginica virginica virginica virginica virginica virginica
But if I want to substring the characters 1 through 3, for example, i get the following error: 但是,例如,如果我想对字符串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
What guidelines are there to modifying columns in an ffdf object? 有什么准则可以修改ffdf对象中的列?
Edit 编辑
I also tried the ffdfdply approach. 我也尝试了ffdfdply方法。 It seems to take really long for a reasonably small data: 相当小的数据似乎要花很长时间:
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))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.