我有一个以下格式的数据框 Original format
对于给定的ID;年龄,性别和地位保持不变。
我想做一些转换
下面附有所需的输出格式以供参考。desired format
我尝试过使用dcast和reshape; tidyr与dplyr使用聚集和传播,但是无法实现第3次转换
任何帮助都会很棒!感谢
答案 0 :(得分:1)
您可以使用<jaxws:client id="service1"
serviceClass="com.Service1" address="${E1}"
username="${U1}" password="${P1}">
<jaxws:features>
<beans:bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>
<jaxws:handlers>
<beans:bean class="com.SOAPMessageLoggingHandler" />
</jaxws:handlers>
</jaxws:client>
<jaxws:client id="service2"
serviceClass="com.Service2" address="${E2}"
username="${U2}" password="${P2}">
<jaxws:features>
<beans:bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>
</jaxws:client>
包中的<jaxws:client id="service2"
serviceClass="com.Service2" address="${E2}"
username="${U2}" password="${P2}">
<jaxws:features>
<beans:bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>
</jaxws:client>
<jaxws:client id="service1"
serviceClass="com.Service1" address="${E1}"
username="${U1}" password="${P1}">
<jaxws:features>
<beans:bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>
<jaxws:handlers>
<beans:bean class="com.SOAPMessageLoggingHandler" />
</jaxws:handlers>
</jaxws:client>
功能:
设置包和数据:
spread()
使用tidyr
按ID和类型获取结果。
使用library(dplyr)
library(tidyr)
df=data.frame(
id=c(1,1,1,1,1,2,2),
age=c(3,3,3,3,3,51,51),
sex=c('f','f','f','f','f','m','m'),
type=c('a','a','a','b','b','a','a'),
tablet=c('t1','t2','t3','t1','t5','t3','t10'),
level=c(1,2,3,1,4,2,3),
status=c('n','n','n','n','n','y','y')
)
转换包含列名称的group_by()
列的数据,以及包含值的spread()
列。 tablet
默认情况下会填充level
的空白。
使用spread()
将列重新排列为所需的格式:
NA