如何使用:在H2O ddply,R中起作用? [英] How to use : function in H2O ddply, R?

查看:60
本文介绍了如何使用:在H2O ddply,R中起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下代码:

library(h2o)
library(plyr)

h2o.init()
data1x <- "x row1
1 1
1 2
1 3
1 4
2 1
2 2
2 3
3 1
4 2"
data1x <- read.table(textConnection(data1x), header=TRUE)
data1xH2O <- as.h2o(data1x)

fun = function(df) {
  1:2
}

h2o.ddply(data1xH2O, "x", fun)

ddply(data1x, "x", fun)

dd20的h20版本给出以下错误.

The h20 version of ddply gives below error.

ERROR: Unexpected HTTP Status code: 400 Bad Request (url = http://localhost:54321/99/Rapids)

water.rapids.Rapids.IllegalASTException
 [1] "water.rapids.Rapids$IllegalASTException: Missing a number"                                                   
 [2] "    water.rapids.Rapids.number(Rapids.java:312)"                                                             
 [3] "    water.rapids.Rapids.parseNumList(Rapids.java:243)"                                                       
 [4] "    water.rapids.Rapids.parseList(Rapids.java:208)"                                                          
 [5] "    water.rapids.Rapids.parseNext(Rapids.java:140)"                                                          
 [6] "    water.rapids.Rapids.parseFunctionDefinition(Rapids.java:193)"                                            
 [7] "    water.rapids.Rapids.parseNext(Rapids.java:139)"                                                          
 [8] "    water.rapids.Rapids.parseFunctionApplication(Rapids.java:158)"                                           
 [9] "    water.rapids.Rapids.parseNext(Rapids.java:138)"                                                          
[10] "    water.rapids.Rapids.parseFunctionApplication(Rapids.java:158)"                                           
[11] "    water.rapids.Rapids.parseNext(Rapids.java:138)"                                                          
[12] "    water.rapids.Rapids.parse(Rapids.java:48)"                                                               
[13] "    water.rapids.Rapids.exec(Rapids.java:81)"                                                                
[14] "    water.api.RapidsHandler.exec(RapidsHandler.java:39)"                                                     
[15] "    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)"                                             
[16] "    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)"                           
[17] "    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)"                   
[18] "    java.lang.reflect.Method.invoke(Method.java:483)"                                                        
[19] "    water.api.Handler.handle(Handler.java:61)"                                                               
[20] "    water.api.RequestServer.serve(RequestServer.java:412)"                                                   
[21] "    water.api.RequestServer.doGeneric(RequestServer.java:263)"                                               
[22] "    water.api.RequestServer.doPost(RequestServer.java:200)"                                                  
[23] "    javax.servlet.http.HttpServlet.service(HttpServlet.java:755)"                                            
[24] "    javax.servlet.http.HttpServlet.service(HttpServlet.java:848)"                                            
[25] "    org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)"                                  
[26] "    org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503)"                              
[27] "    org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)"                           
[28] "    org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)"                             
[29] "    org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)"                       
[30] "    org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)"                      
[31] "    org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429)"                               
[32] "    org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)"                        
[33] "    org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)"                       
[34] "    org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)"                           
[35] "    org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)"                   
[36] "    org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)"                         
[37] "    org.eclipse.jetty.server.Server.handle(Server.java:370)"                                                 
[38] "    org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)"          
[39] "    org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:53)"           
[40] "    org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:982)"                
[41] "    org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1043)"
[42] "    org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)"                                        
[43] "    org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)"                                   
[44] "    org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:72)"                  
[45] "    org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:264)"            
[46] "    org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)"                        
[47] "    org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)"                         
[48] "    java.lang.Thread.run(Thread.java:745)"                                                                   

Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, urlSuffix = page,  : 

ERROR MESSAGE:

Missing a number

plyr包中ddply的相同代码起作用. 请提出任何建议.

The same code for ddply from plyr package works. Please give any suggestion.

推荐答案

问题是您的函数对数据框没有任何作用,并且根据函数定义,不清楚目标是什么.

The problem is that your function does nothing with respect the dataframe and based on your function definition it is not clear what your objective is.

乐趣= function(df){ 1:2 }

fun = function(df) { 1:2 }

如果查看h2o.ddply函数文档,您将看到此函数用于基于某些条件将函数应用于完整数据集.

if you look at h2o.ddply function documentation you will see that this function is used to apply a function on full data set based on certain criteria.

我已将您的上述示例更改如下,以更好地解释它:

I have changed your above example as below to explain it better:

> data1xH2O
   x row1
 1 1    1  
 2 1    2
 3 1    3
 4 1    4
 5 2    1
 6 2    2
 > fun1 = function(df) { df[,1]}
 > h2o.ddply(data1xH2O, 1:2, fun1)
     x row1 ddply_C1
   1 1    1        1
   2 1    2        1
   3 1    3        1
   4 1    4        1
   5 2    1        2
   6 2    2        2

fun1上方是从传递的数据框中提取我们的列.再一次,如果我将fun更改为fun2,如下所示:

Above the fun1 is extracting our column out from passed dataframe. Again if I change the fun to fun2 as below:

 > fun2 = function(df) { df[,2]}
 > h2o.ddply(data1xH2O, 1:2, fun2)
     x row1 ddply_C1
   1 1    1        1
   2 1    2        2
   3 1    3        3
   4 1    4        4
   5 2    1        1
   6 2    2        2

这篇关于如何使用:在H2O ddply,R中起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆