如何创建一个for循环,将多个数据帧和df子集组合到一个数据帧中?

时间:2019-12-19 09:32:58

标签: r dataframe for-loop

我正在尝试修改数据帧,并努力将我的操作组合到一个for循环中。我想根据一个特定的列对数据帧进行子集处理,将不同的行附加到每个子集,然后将修改后的子集再次组合到一个单个数据帧中。让我们以虹膜数据为例:

#Create data frame subsets based on Species column
iris_subs <- split(iris, iris$Species)

#create an empty data frame with the same columns as in iris and one empty row
emptydf <- iris[FALSE,]
emptydf[nrow(emptydf)+1,] <- NA

#create a data frame with sums for each species
iris %>% group_by(Species) %>% summarise_all(sum) -> iris_sums
iris_sums <- iris_sums[,-c(1)] #delete column with species names

#Combine data frames into one data frame with original data, sum for this species and an empty row for each subset
iris_setosa <- bind_rows(iris_subs[1], iris_sums[1,], emptydf)
iris_versicolor <- bind_rows(iris_subs[2], iris_sums[2,], emptydf)
iris_virginica <- bind_rows(iris_subs[3], iris_sums[3,], emptydf)
new_iris <- bind_rows(iris_setosa, iris_versicolor, iris_virginica)

此代码完成了工作。但是,我要以这种方式处理数百个数据帧,并且每个数据帧的不同种类的数量各不相同。如何在for循环中自动化最后一部分?

我想要这样的东西

#empty data frame to store output
new_iris <- iris[FALSE,]    

for (i in iris_subs) {
        new_iris[i] <- bind_rows(iris_subs[i], iris_sums[i,], emptydf)
        new_iris <- merge(new_iris[i])
    }

Error in iris_subs[i] : invalid subscript type 'list'

除了错误,这可能太简单了……我是R初学者,已经在网上搜索了几天,但找不到任何答案。有人对如何实现这一目标有建议吗?谢谢您的提示!

2 个答案:

答案 0 :(得分:2)

我们可以创建一个函数,并对所有数据框重复该函数。这是您尝试做的事情的简短版本

library(dplyr)

repeat_process <- function(df) {
   iris_sums <- df %>% group_by(Species) %>% summarise_all(sum) %>% select(-Species)
   df %>% bind_rows(iris_sums, emptydf[rep(1:nrow(emptydf), n_distinct(df$Species)), ])
}

现在让我们假设您有一个数据帧列表

list_df <- list(iris, iris)

您可以将此功能应用于列表中的每个数据框

lapply(list_df, repeat_process)

答案 1 :(得分:1)

您可以定义一个函数,该函数将合计data.frame的所有数字列,并将其他列保留为NA,并将其附加到原始数据框:

2019-12-19 09:11:37,936 INFO  [io.smallrye.metrics] (MSC service thread 1-8) MicroProfile: Metrics activated
2019-12-19 09:11:38,105 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 76) WFLYCLINF0002: Started client-mappings cache from ejb container
2019-12-19 09:11:38,713 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:38] (wrn) Failed to resolve IGNITE_HOME automatically for class codebase [class=class o.a.i.i.util.IgniteUtils, e=URI scheme is not "file"]
2019-12-19 09:11:38,715 ERROR [stderr] (ServerService Thread Pool -- 81)
2019-12-19 09:11:38,722 WARNING [] (ServerService Thread Pool -- 81) Failed to resolve default logging config file: config/java.util.logging.properties
2019-12-19 09:11:38,724 ERROR [stderr] (ServerService Thread Pool -- 81) Console logging handler is not configured.
2019-12-19 09:11:38,727 WARNING [org.apache.ignite.internal.util.typedef.G] (ServerService Thread Pool -- 81) Ignite work directory is not provided, automatically resolved to: /opt/jboss/ignite/work
2019-12-19 09:11:38,871 INFO  [org.apache.ignite.internal.IgniteKernal] (ServerService Thread Pool -- 81)

>>>    __________  ________________
>>>   /  _/ ___/ |/ /  _/_  __/ __/
>>>  _/ // (7 7    // /  / / / _/
>>> /___/\___/_/|_/___/ /_/ /___/
>>>
>>> ver. 2.7.6#20190911-sha1:21f7ca41
>>> 2019 Copyright(C) Apache Software Foundation
>>>
>>> Ignite documentation: http://ignite.apache.org

2019-12-19 09:11:38,875 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:38]    __________  ________________
2019-12-19 09:11:38,876 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:38]   /  _/ ___/ |/ /  _/_  __/ __/
2019-12-19 09:11:38,878 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:38]  _/ // (7 7    // /  / / / _/
2019-12-19 09:11:38,881 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:38] /___/\___/_/|_/___/ /_/ /___/
2019-12-19 09:11:38,881 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:38]
2019-12-19 09:11:38,883 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:38] ver. 2.7.6#20190911-sha1:21f7ca41
2019-12-19 09:11:38,884 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:38] 2019 Copyright(C) Apache Software Foundation
2019-12-19 09:11:38,885 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:38]
2019-12-19 09:11:38,886 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:38] Ignite documentation: http://ignite.apache.org
2019-12-19 09:11:38,887 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:38]
2019-12-19 09:11:38,887 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:38] Quiet mode.
2019-12-19 09:11:38,898 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:38]   ^-- Logging by 'JavaLogger [quiet=true, config=null]'
2019-12-19 09:11:38,899 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:38]   ^-- To see **FULL** console log here add -DIGNITE_QUIET=false or "-v" to ignite.{sh|bat}
2019-12-19 09:11:38,900 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:38]
2019-12-19 09:11:38,900 INFO  [org.apache.ignite.internal.IgniteKernal] (ServerService Thread Pool -- 81) Config URL: n/a
2019-12-19 09:11:38,922 INFO  [org.apache.ignite.internal.IgniteKernal] (ServerService Thread Pool -- 81) IgniteConfiguration [igniteInstanceName=null, pubPoolSize=8, svcPoolSize=8, callbackPoolSize=8, stripedPoolSize=8, sysPoolSize=8, mgmtPoolSize=4, igfsPoolSize=4, dataStreamerPoolSize=8, utilityCachePoolSize=8, utilityCacheKeepAliveTime=60000, p2pPoolSize=2, qryPoolSize=8, igniteHome=null, igniteWorkDir=/opt/jboss/ignite/work, mbeanSrv=org.jboss.as.jmx.PluggableMBeanServerImpl@6dfabbe3, nodeId=518ef744-d8da-41e4-a907-a2d8b541e89c, marsh=BinaryMarshaller [], marshLocJobs=false, daemon=false, p2pEnabled=false, netTimeout=5000, sndRetryDelay=1000, sndRetryCnt=3, metricsHistSize=10000, metricsUpdateFreq=2000, metricsExpTime=9223372036854775807, discoSpi=TcpDiscoverySpi [addrRslvr=null, sockTimeout=0, ackTimeout=0, marsh=null, reconCnt=10, reconDelay=2000, maxAckTimeout=600000, forceSrvMode=false, clientReconnectDisabled=false, internalLsnr=null], segPlc=STOP, segResolveAttempts=2, waitForSegOnStart=true, allResolversPassReq=true, segChkFreq=10000, commSpi=TcpCommunicationSpi [connectGate=null, connPlc=org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$FirstConnectionPolicy@612791b7, enableForcibleNodeKill=false, enableTroubleshootingLog=false, locAddr=null, locHost=null, locPort=47100, locPortRange=100, shmemPort=-1, directBuf=true, directSndBuf=false, idleConnTimeout=600000, connTimeout=5000, maxConnTimeout=600000, reconCnt=10, sockSndBuf=32768, sockRcvBuf=32768, msgQueueLimit=0, slowClientQueueLimit=0, nioSrvr=null, shmemSrv=null, usePairedConnections=false, connectionsPerNode=1, tcpNoDelay=true, filterReachableAddresses=false, ackSndThreshold=32, unackedMsgsBufSize=0, sockWriteTimeout=2000, boundTcpPort=-1, boundTcpShmemPort=-1, selectorsCnt=4, selectorSpins=0, addrRslvr=null, ctxInitLatch=java.util.concurrent.CountDownLatch@3ba79825[Count = 1], stopping=false], evtSpi=org.apache.ignite.spi.eventstorage.NoopEventStorageSpi@56c02b1c, colSpi=NoopCollisionSpi [], deploySpi=LocalDeploymentSpi [], indexingSpi=org.apache.ignite.spi.indexing.noop.NoopIndexingSpi@7368d9cb, addrRslvr=null, encryptionSpi=org.apache.ignite.spi.encryption.noop.NoopEncryptionSpi@24279471, clientMode=true, rebalanceThreadPoolSize=1, txCfg=TransactionConfiguration [txSerEnabled=false, dfltIsolation=REPEATABLE_READ, dfltConcurrency=PESSIMISTIC, dfltTxTimeout=0, txTimeoutOnPartitionMapExchange=0, pessimisticTxLogSize=0, pessimisticTxLogLinger=10000, tmLookupClsName=null, txManagerFactory=null, useJtaSync=false], cacheSanityCheckEnabled=true, discoStartupDelay=60000, deployMode=SHARED, p2pMissedCacheSize=100, locHost=null, timeSrvPortBase=31100, timeSrvPortRange=100, failureDetectionTimeout=10000, sysWorkerBlockedTimeout=null, clientFailureDetectionTimeout=30000, metricsLogFreq=60000, hadoopCfg=null, connectorCfg=ConnectorConfiguration [jettyPath=null, host=null, port=11211, noDelay=true, directBuf=false, sndBufSize=32768, rcvBufSize=32768, idleQryCurTimeout=600000, idleQryCurCheckFreq=60000, sndQueueLimit=0, selectorCnt=4, idleTimeout=7000, sslEnabled=false, sslClientAuth=false, sslCtxFactory=null, sslFactory=null, portRange=100, threadPoolSize=8, msgInterceptor=null], odbcCfg=null, warmupClos=null, atomicCfg=AtomicConfiguration [seqReserveSize=1000, cacheMode=PARTITIONED, backups=1, aff=null, grpName=null], classLdr=null, sslCtxFactory=null, platformCfg=null, binaryCfg=null, memCfg=null, pstCfg=null, dsCfg=null, activeOnStart=true, autoActivation=true, longQryWarnTimeout=3000, sqlConnCfg=null, cliConnCfg=ClientConnectorConfiguration [host=null, port=10800, portRange=100, sockSndBufSize=0, sockRcvBufSize=0, tcpNoDelay=true, maxOpenCursorsPerConn=128, threadPoolSize=8, idleTimeout=0, jdbcEnabled=true, odbcEnabled=true, thinCliEnabled=true, sslEnabled=false, useIgniteSslCtxFactory=true, sslClientAuth=false, sslCtxFactory=null], mvccVacuumThreadCnt=2, mvccVacuumFreq=5000, authEnabled=false, failureHnd=null, commFailureRslvr=null]
2019-12-19 09:11:38,923 INFO  [org.apache.ignite.internal.IgniteKernal] (ServerService Thread Pool -- 81) Daemon mode: off
2019-12-19 09:11:38,925 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:38] OS: Linux 4.9.184-linuxkit amd64
2019-12-19 09:11:38,926 INFO  [org.apache.ignite.internal.IgniteKernal] (ServerService Thread Pool -- 81) OS: Linux 4.9.184-linuxkit amd64
2019-12-19 09:11:38,927 INFO  [org.apache.ignite.internal.IgniteKernal] (ServerService Thread Pool -- 81) OS user: jboss
2019-12-19 09:11:38,937 INFO  [org.apache.ignite.internal.IgniteKernal] (ServerService Thread Pool -- 81) PID: 318
2019-12-19 09:11:38,938 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:38] VM information: OpenJDK Runtime Environment 11.0.5+10-LTS Oracle Corporation OpenJDK 64-Bit Server VM 11.0.5+10-LTS
2019-12-19 09:11:38,939 INFO  [org.apache.ignite.internal.IgniteKernal] (ServerService Thread Pool -- 81) Language runtime: Java Platform API Specification ver. 11
2019-12-19 09:11:38,940 INFO  [org.apache.ignite.internal.IgniteKernal] (ServerService Thread Pool -- 81) VM information: OpenJDK Runtime Environment 11.0.5+10-LTS Oracle Corporation OpenJDK 64-Bit Server VM 11.0.5+10-LTS
2019-12-19 09:11:38,941 INFO  [org.apache.ignite.internal.IgniteKernal] (ServerService Thread Pool -- 81) VM total memory: 0.5GB
2019-12-19 09:11:38,942 INFO  [org.apache.ignite.internal.IgniteKernal] (ServerService Thread Pool -- 81) Remote Management [restart: off, REST: off, JMX (remote: off)]
2019-12-19 09:11:38,943 INFO  [org.apache.ignite.internal.IgniteKernal] (ServerService Thread Pool -- 81) Logger: JavaLogger [quiet=true, config=null]
2019-12-19 09:11:38,943 INFO  [org.apache.ignite.internal.IgniteKernal] (ServerService Thread Pool -- 81) IGNITE_HOME=null
2019-12-19 09:11:38,944 INFO  [org.apache.ignite.internal.IgniteKernal] (ServerService Thread Pool -- 81) VM arguments: [-D[Standalone], -Xms64m, -Xmx512m, -XX:MetaspaceSize=96M, -XX:MaxMetaspaceSize=256m, -Djava.net.preferIPv4Stack=true, -Djboss.modules.system.pkgs=org.jboss.byteman, -Djava.awt.headless=true, --add-exports=java.base/sun.nio.ch=ALL-UNNAMED, --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED, --add-exports=jdk.unsupported/sun.reflect=ALL-UNNAMED, -Dorg.jboss.boot.log.file=/opt/jboss/wildfly/standalone/log/server.log, -Dlogging.configuration=file:/opt/jboss/wildfly/standalone/configuration/logging.properties]
2019-12-19 09:11:38,957 INFO  [org.apache.ignite.internal.IgniteKernal] (ServerService Thread Pool -- 81) Configured caches [in 'sysMemPlc' dataRegion: ['ignite-sys-cache']]
2019-12-19 09:11:38,967 WARNING [org.apache.ignite.internal.GridDiagnostic] (pub-#22) Initial heap size is 64MB (should be no less than 512MB, use -Xms512m -Xmx512m).
2019-12-19 09:11:38,978 INFO  [stdout] (pub-#22) [09:11:38] Initial heap size is 64MB (should be no less than 512MB, use -Xms512m -Xmx512m).
2019-12-19 09:11:39,063 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:39] Configured plugins:
2019-12-19 09:11:39,064 INFO  [org.apache.ignite.internal.processors.plugin.IgnitePluginProcessor] (ServerService Thread Pool -- 81) Configured plugins:
2019-12-19 09:11:39,064 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:39]   ^-- None
2019-12-19 09:11:39,065 INFO  [org.apache.ignite.internal.processors.plugin.IgnitePluginProcessor] (ServerService Thread Pool -- 81)   ^-- None
2019-12-19 09:11:39,066 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:39]
2019-12-19 09:11:39,067 INFO  [org.apache.ignite.internal.processors.plugin.IgnitePluginProcessor] (ServerService Thread Pool -- 81)
2019-12-19 09:11:39,071 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:39] Configured failure handler: [hnd=StopNodeOrHaltFailureHandler [tryStop=false, timeout=0, super=AbstractFailureHandler [ignoredFailureTypes=[SYSTEM_WORKER_BLOCKED, SYSTEM_CRITICAL_OPERATION_TIMEOUT]]]]
2019-12-19 09:11:39,071 INFO  [org.apache.ignite.internal.processors.failure.FailureProcessor] (ServerService Thread Pool -- 81) Configured failure handler: [hnd=StopNodeOrHaltFailureHandler [tryStop=false, timeout=0, super=AbstractFailureHandler [ignoredFailureTypes=[SYSTEM_WORKER_BLOCKED, SYSTEM_CRITICAL_OPERATION_TIMEOUT]]]]
2019-12-19 09:11:39,121 INFO  [org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi] (ServerService Thread Pool -- 81) Successfully bound communication NIO server to TCP port [port=47100, locHost=0.0.0.0/0.0.0.0, selectorsCnt=4, selectorSpins=0, pairedConn=false]
2019-12-19 09:11:39,125 WARNING [org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi] (ServerService Thread Pool -- 81) Message queue limit is set to 0 which may lead to potential OOMEs when running cache operations in FULL_ASYNC or PRIMARY_SYNC modes due to message queues growth on sender and receiver sides.
2019-12-19 09:11:39,126 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:39] Message queue limit is set to 0 which may lead to potential OOMEs when running cache operations in FULL_ASYNC or PRIMARY_SYNC modes due to message queues growth on sender and receiver sides.
2019-12-19 09:11:39,147 WARNING [org.apache.ignite.spi.checkpoint.noop.NoopCheckpointSpi] (ServerService Thread Pool -- 81) Checkpoints are disabled (to enable configure any GridCheckpointSpi implementation)
2019-12-19 09:11:39,183 WARNING [org.apache.ignite.internal.managers.collision.GridCollisionManager] (ServerService Thread Pool -- 81) Collision resolution is disabled (all jobs will be activated upon arrival).
2019-12-19 09:11:39,190 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:39] Security status [authentication=off, tls/ssl=off]
2019-12-19 09:11:39,191 INFO  [org.apache.ignite.internal.IgniteKernal] (ServerService Thread Pool -- 81) Security status [authentication=off, tls/ssl=off]
2019-12-19 09:11:39,341 SEVERE [org.apache.ignite.internal.IgniteKernal] (ServerService Thread Pool -- 81) Exception during start processors, node will be stopped and close connections: class org.apache.ignite.binary.BinaryObjectException: Failed to find empty constructor for class: org.apache.ignite.internal.processors.platform.websession.PlatformDotNetSessionLockResult
    at deployment.StreamsApp.ear//org.apache.ignite.internal.binary.BinaryClassDescriptor.constructor(BinaryClassDescriptor.java:981)
    at deployment.StreamsApp.ear//org.apache.ignite.internal.binary.BinaryClassDescriptor.<init>(BinaryClassDescriptor.java:267)
    at deployment.StreamsApp.ear//org.apache.ignite.internal.binary.BinaryContext.registerPredefinedType(BinaryContext.java:1063)
    at deployment.StreamsApp.ear//org.apache.ignite.internal.binary.BinaryContext.registerPredefinedType(BinaryContext.java:1048)

2019-12-19 09:11:39,355 SEVERE [org.apache.ignite.internal.IgniteKernal] (ServerService Thread Pool -- 81) Got exception while starting (will rollback startup routine).: class org.apache.ignite.binary.BinaryObjectException: Failed to find empty constructor for class: org.apache.ignite.internal.processors.platform.websession.PlatformDotNetSessionLockResult
    at deployment.StreamsApp.ear//org.apache.ignite.internal.binary.BinaryClassDescriptor.constructor(BinaryClassDescriptor.java:981)
    at deployment.StreamsApp.ear//org.apache.ignite.internal.binary.BinaryClassDescriptor.<init>(BinaryClassDescriptor.java:267)
    at deployment.StreamsApp.ear//org.apache.ignite.internal.binary.BinaryContext.registerPredefinedType(BinaryContext.java:1063)
    at deployment.StreamsApp.ear//org.apache.ignite.internal.binary.BinaryContext.registerPredefinedType(BinaryContext.java:1048)
    at deployment.StreamsApp.ear//org.apache.ignite.internal.binary.BinaryContext.<init>(BinaryContext.java:350)
    at deployment.StreamsApp.ear//org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl.start(CacheObjectBinaryProcessorImpl.java:208)
    at deployment.StreamsApp.ear//org.apache.ignite.internal.IgniteKernal.startProcessor(IgniteKernal.java:1700)
    at deployment.StreamsApp.ear//org.apache.ignite.internal.IgniteKernal.start(IgniteKernal.java:1013)
    at deployment.StreamsApp.ear//org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start0(IgnitionEx.java:2038)
    at org.jboss.as.ee@18.0.1.Final//org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:88)
    at org.jboss.as.ejb3@18.0.1.Final//org.jboss.as.ejb3.component.singleton.SingletonComponent.getComponentInstance(SingletonComponent.java:127)
    at org.jboss.as.ejb3@18.0.1.Final//org.jboss.as.ejb3.component.singleton.SingletonComponent.start(SingletonComponent.java:141)
    at org.jboss.as.ee@18.0.1.Final//org.jboss.as.ee.component.ComponentStartService$1.run(ComponentStartService.java:54)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at org.jboss.threads@2.3.3.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)
    at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
    at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1348)
    at java.base/java.lang.Thread.run(Thread.java:834)
    at org.jboss.threads@2.3.3.Final//org.jboss.threads.JBossThread.run(JBossThread.java:485)

2019-12-19 09:11:39,364 WARNING [org.apache.ignite.internal.IgniteKernal] (ServerService Thread Pool -- 81) Attempt to stop starting grid. This operation cannot be guaranteed to be successful.
2019-12-19 09:11:39,380 INFO  [stdout] (ServerService Thread Pool -- 81) [09:11:39] Ignite node stopped OK [uptime=00:00:02.180]
2019-12-19 09:11:39,381 INFO  [org.apache.ignite.internal.IgniteKernal] (ServerService Thread Pool -- 81)

>>> +---------------------------------------------------------------------------------+
>>> Ignite ver. 2.7.6#20190911-sha1:21f7ca41c4348909e2fd26ccf59b5b2ce1f4474e stopped OK
>>> +---------------------------------------------------------------------------------+
>>> Grid uptime: 00:00:02.180


2019-12-19 09:11:39,404 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 81) MSC000001: Failed to start service jboss.deployment.subunit."StreamsApp.ear"."Streams.jar".component.Main.START: org.jboss.msc.service.StartException in service jboss.deployment.subunit."StreamsApp.ear"."Streams.jar".component.Main.START: java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance
    at org.jboss.as.ee@18.0.1.Final//org.jboss.as.ee.component.ComponentStartService$1.run(ComponentStartService.java:57)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at org.jboss.threads@2.3.3.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)
    at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
    at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1348)
    at java.base/java.lang.Thread.run(Thread.java:834)
    at org.jboss.threads@2.3.3.Final//org.jboss.threads.JBossThread.run(JBossThread.java:485)
Caused by: java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance
    at org.jboss.as.ee@18.0.1.Final//org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:163)
    at org.jboss.as.ee@18.0.1.Final//org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:134)
    at org.jboss.as.ee@18.0.1.Final//org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:88)
    at org.jboss.as.ejb3@18.0.1.Final//org.jboss.as.ejb3.component.singleton.SingletonComponent.getComponentInstance(SingletonComponent.java:127)
    at org.jboss.as.ejb3@18.0.1.Final//org.jboss.as.ejb3.component.singleton.SingletonComponent.start(SingletonComponent.java:141)
    at org.jboss.as.ee@18.0.1.Final//org.jboss.as.ee.component.ComponentStartService$1.run(ComponentStartService.java:54)
    ... 8 more
Caused by: javax.ejb.EJBException: class org.apache.ignite.binary.BinaryObjectException: Failed to find empty constructor for class: org.apache.ignite.internal.processors.platform.websession.PlatformDotNetSessionLockResult
    at org.jboss.as.ejb3@18.0.1.Final//org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:246)

    ... 13 more
Caused by: class org.apache.ignite.binary.BinaryObjectException: Failed to find empty constructor for class: org.apache.ignite.internal.processors.platform.websession.PlatformDotNetSessionLockResult
    at deployment.StreamsApp.ear//org.apache.ignite.internal.binary.BinaryClassDescriptor.constructor(BinaryClassDescriptor.java:981)
    at deployment.StreamsApp.ear//org.apache.ignite.internal.binary.BinaryClassDescriptor.<init>(BinaryClassDescriptor.java:267)
    at deployment.StreamsApp.ear//org.apache.ignite.internal.binary.BinaryContext.registerPredefinedType(BinaryContext.java:1063)
    at deployment.StreamsApp.ear.Streams.jar//ru.sbrf.streams.cache.IgniteInitializer.init(IgniteInitializer.java:34)
    at deployment.StreamsApp.ear.Streams.jar//ru.sbrf.streams.Main.startup(Main.java:23)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.jboss.as.ee@18.0.1.Final//org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptor.java:96)
    at org.jboss.invocation@1.5.2.Final//org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.invocation@1.5.2.Final//org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:509)
    at org.jboss.as.weld.common@18.0.1.Final//org.jboss.as.weld.interceptors.Jsr299BindingsInterceptor.delegateInterception(Jsr299BindingsInterceptor.java:79)
    at org.jboss.as.weld.common@18.0.1.Final//org.jboss.as.weld.interceptors.Jsr299BindingsInterceptor.doLifecycleInterception(Jsr299BindingsInterceptor.java:126)
    at org.jboss.as.weld.common@18.0.1.Final//org.jboss.as.weld.interceptors.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:112)
    at org.jboss.invocation@1.5.2.Final//org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.invocation@1.5.2.Final//org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:509)
    at org.jboss.weld.core@3.1.2.Final//org.jboss.weld.module.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:81)
    at org.jboss.as.weld.common@18.0.1.Final//org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:89)
    at org.jboss.invocation@1.5.2.Final//org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.ee@18.0.1.Final//org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
    at org.jboss.invocation@1.5.2.Final//org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.ejb3@18.0.1.Final//org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:237)
    ... 28 more

2019-12-19 09:11:39,471 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 2) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "StreamsApp.ear")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.subunit.\"StreamsApp.ear\".\"Streams.jar\".component.Main.START" => "java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance
    Caused by: java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance
    Caused by: javax.ejb.EJBException: class org.apache.ignite.binary.BinaryObjectException: Failed to find empty constructor for class: org.apache.ignite.internal.processors.platform.websession.PlatformDotNetSessionLockResult
    Caused by: class org.apache.ignite.binary.BinaryObjectException: Failed to find empty constructor for class: org.apache.ignite.internal.processors.platform.websession.PlatformDotNetSessionLockResult"}}
2019-12-19 09:11:39,546 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0010: Deployed "StreamsApp.ear" (runtime-name : "StreamsApp.ear")
2019-12-19 09:11:39,548 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) WFLYCTL0183: Service status report
WFLYCTL0186:   Services which failed to start:      service jboss.deployment.subunit."StreamsApp.ear"."Streams.jar".component.Main.START: java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance
WFLYCTL0448: 2 additional services are down due to their dependencies being missing or failed

然后我们使用purrr映射每个子集:

numericCols = sapply(iris,is.numeric)

func = function(df,numCols){

iris_sums <- colSums(df[,numCols])
result <- rep(NA,ncol(df))
names(result) <- colnames(df)
result[names(iris_sums)] <- iris_sums
rbind(df,result,rep(NA,ncol(df)))
}