如何将具有两列的数据帧重新整形为宽格式?(How to reshape a data frame with two columns to wide format?)
我想重塑以下数据框架
x <- structure( list(name = c("HT", "AT", "HG", "AG"), conv = c(2L, + 2L, 3L, 4L)), .Names = c("name", "conv"), row.names = 1:4, class = "data.frame") > x name conv 1 HT 2 2 AT 2 3 HG 3 4 AG 4
成
conv x.1 x.2 1 2 HT AT 2 3 HG NA 3 4 AG NA
在最终数据框中,对于
conv
每个不同值,应该有一行,以及多少x.?
列,因为原始数据帧中有特定值的conv
,在必要时填充NA。 我不关心列名。我尝试
reshape
但我无法让它工作,因为它似乎需要第三列,我没有:> reshape(x, idvar='conv', direction='wide') Error in `[.data.frame`(data, , timevar) : undefined columns selected
I want to reshape the following data frame
x <- structure( list(name = c("HT", "AT", "HG", "AG"), conv = c(2L, + 2L, 3L, 4L)), .Names = c("name", "conv"), row.names = 1:4, class = "data.frame") > x name conv 1 HT 2 2 AT 2 3 HG 3 4 AG 4
into
conv x.1 x.2 1 2 HT AT 2 3 HG NA 3 4 AG NA
In the final data frame there should be a row for every distinct value of
conv
, and as manyx.?
columns as there are rows in the original data frame for that particular value ofconv
, filling with NAs when necessary. I don't care about the column names.I tried
reshape
but I can't get it to work, because it seems that it needs a third column that I don't have:> reshape(x, idvar='conv', direction='wide') Error in `[.data.frame`(data, , timevar) : undefined columns selected
原文:https://stackoverflow.com/questions/29415194
满意答案
没有标准的JAXB(JSR-222)方法从XML模式生成以下类。
@XmlRootElement public class Customer { private Map<String, Address> addressMap = new HashMap<String, Address>(); public Map<String, Address> getAddressMap() { return addressMap; } public void setAddressMap(Map<String, Address> addressMap) { this.addressMap = addressMap; } }
There isn't a standard JAXB (JSR-222) way to generate the following class from an XML schema.
@XmlRootElement public class Customer { private Map<String, Address> addressMap = new HashMap<String, Address>(); public Map<String, Address> getAddressMap() { return addressMap; } public void setAddressMap(Map<String, Address> addressMap) { this.addressMap = addressMap; } }
相关问答
更多jaxb xjc - 如何生成单元测试文件(jaxb xjc - how to generate unit test files)
使JAXB XJC为简单类型生成一个包装类(Make JAXB XJC generate a wrapping class for a simple type)
JAXB xjc映射到现有的域对象(JAXB xjc mapping to existing domain objects)
XJC生成的命名空间(XJC generated namespaces)
JAXB XJC抑制ObjectFactory并生成jaxb.index(JAXB XJC Suppress ObjectFactory & Generate jaxb.index)
JAXB:具有文本内容和属性的元素,使用XJC生成类(JAXB: an element with textual content and attributes, generating classes with XJC)
如何使用JAXB XJC从外部XSD文件生成类(How can I generate classes from outside XSD file using JAXB XJC)
JaxB xjc生成的pojos包含空名称空间(JaxB xjc generated pojos contains blank namespaces)
JAXB - XJC设置不生成Map to Key-Value对转换位直接绑定(JAXB - XJC settings not to generate Map to List of Key-Value pair conversion bit direct binding)
为什么XJC生成@XmlElementRefs(Why XJC generates @XmlElementRefs)
相关文章
更多XnView Format
Becoming a data scientist
Spring Data: a new perspective of data operations
Hadoop格式化失败原因 Format aborted in path
HADOOP NAMENODE FORMAT过程分析
(二)solr data import
《Big Data Glossary》笔记
Hadoop教程:NameNode的format操作做了什么
自己封装的一个Solr Data Import Request Handler Scheduler
Spark - A Fault-Tolerant Abstraction for In-Memory Cluster Computing
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!