在rmongodb中运行mongo.cursor.to.data.frame函数时出现警告消息
当我运行查询时在rmongodb中运行mongo.cursor.to.data.frame函数时出现警告消息,r,rmongodb,R,Rmongodb,当我运行查询时 mongo.cursor.to.data.frame(cursor) 要使用rmongodb将集合中的文档提取到R中的数据帧,我收到警告消息: In mongo.cursor.to.data.frame(cursor) : This fails for most NoSQL data structures. I am working on a new solution 我查看了一些关于rmongodb的文章,我也发现了上面提到的这条消息。此警告是否意味着结果数据框中可能存在一
mongo.cursor.to.data.frame(cursor)
要使用rmongodb
将集合中的文档提取到R中的数据帧,我收到警告消息:
In mongo.cursor.to.data.frame(cursor) : This fails for most NoSQL data structures. I am working on a new solution
我查看了一些关于rmongodb的文章,我也发现了上面提到的这条消息。此警告是否意味着结果数据框中可能存在一些问题?显示了问题可能出现的位置
mongo.cursor.to.data.frame <- function(cursor, nullToNA=TRUE, ...){
warning("This fails for most NoSQL data structures. I am working on a new solution")
res <- data.frame()
while ( mongo.cursor.next(cursor) ){
val <- mongo.bson.to.list(mongo.cursor.value(cursor))
if( nullToNA == TRUE )
val[sapply(val, is.null)] <- NA
# remove mongo.oid -> data.frame can not deal with that!
val <- val[sapply(val, class) != 'mongo.oid']
res <- rbind.fill(res, as.data.frame(val, ... ))
}
return( as.data.frame(res) )
}
在这一点上,我应该提到这个包,它通常更快,但再次返回一个
data.frame
还有我对mongolite的扩展(还没有在CRAN上),它更快,检索数据也更快,但同样受到限制,结果必须强制转换为数据。表
## consider the JSON structure
## [{"a":[1,2,3],"b":["a","b","c"]},{"d":[1.1,2.2,3.3],"e":[["nested","list"]]}]
##Which in R is the same as
lst = list(list(a = c(1L,2L,3L),
b = c("a","b","c")),
list(d = c(1.1, 2.2, 3.3),
e = list(c("nested", "list"))))
## this errors when coerced to a data.frame
as.data.frame(lst)
Error in data.frame(d = c(1.1, 2.2, 3.3), e = list(c("nested", "list")), :
arguments imply differing number of rows: 3, 2