问题标签 [reformat]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
100 浏览

r - 在 R 中重新格式化分类数据

我有一个分类数据集,我试图总结它在所问问题的性质上存在固有差异。下面的数据代表一份问卷,其中包含标准的封闭式问题,但也包含可以从列表中选择多个答案的问题。“村庄”和“收入”代表封闭式问题。“responsible.1”...等...代表一个列表,其中受访者对每个人都说是或否。

我想要的是一个 3 路表输出,其中包含“村庄”和一套“负责任”负责变量包装成ftable. 这样,我可以使用带有大量 R 包的表格进行图表和分析。

as.data.frame(table(village, responsible.1)会让我成为第一个,但我不知道如何将整个事情包裹在一个不错的ftable.

0 投票
2 回答
4063 浏览

json - JSON删除空格和回车,但保留引号中的空格

我需要这样的 JSON 对象:

并删除所有回车和不在引号中的空格。所以结果应该是这样的:

引号内的空格需要保留。

一个 jQuery 解决方案很好。

谢谢!

-马特

0 投票
1 回答
890 浏览

arrays - R:在数组上应用 ecdf 函数

起初我有一个这样的矩阵:

然后是一个数组

该数组是 52(周)的 Dataframe 序列。这是一个时间分析(每周)

我想在这个数组上计算一个 ecdf 函数。

计算每个单元格的 ecdf 函数。这是每周的季节性分析。

即计算这个时间序列的分位数(**):0.66319631;-0.79365987;1.03862172

对于 MEAN,它的工作原理:

我尝试了与 ecdf 类似的功能,但它不起作用。

然后......它还没有完成,我想像数据数据帧(x)的原始格式一样重新格式化这个数组。(就像一个 rbind 但在一个数组上。)

非常感谢你的帮助。

编辑 :

对不起,但我不知道我是否这么清楚。数组对我来说很复杂;

但是用你的方法,如果我有这个简单的数据框:

你的函数给出:

或者我会更多这样的东西:

并得到一个表格,它是时间序列的百分位值。每列和每行的百分位值分别为 1 和 11、2 和 12(我知道这无关紧要,但仅作为示例)

抱歉,如果我的最后一个问题无法理解

0 投票
1 回答
26 浏览

vim - 在 Vim 中粘贴和重新格式化文本不是通过快捷方式而是通过命令

我正在尝试编写一个脚本,它将剪贴板中的文本粘贴到 Vim 的当前缓冲区中,设置新的 textwidth 值、新的文件类型,然后根据这些新设置重新格式化(gggqG 键组合)这个缓冲区。

是否可以将所有这些动作再现为一系列命令?

0 投票
1 回答
33 浏览

performance - 重新格式化代码后的 WebStorm - 这是什么?

这是我的 HTML 结构:

当我使用 WebStorm 的重新格式化代码 ( Alt + Command + L) 时,它变为:

为什么这样做。为什么属性字符串和标签之间有空格?

0 投票
0 回答
28 浏览

vim - vim 行重新格式化缩进

我正在尝试浏览我写的一些 doxygen 评论并重新格式化这些行以使其更具可读性gq- 所以我有这样的东西。

然后我gqsmartindentset 完成它并得到这个:

但我真正想要的是:

我觉得应该有一种快速的方法可以在 vim 中执行此操作,但我似乎无法弄清楚。

0 投票
2 回答
87 浏览

r - R: reshape2 long to wide replacing real values with integers between 1 and 3

Please bear with me since I'm a first time poster. I am attempting to take time series data from long format to wide format, but reshape2 (and reshape) are not outputting what I want. I am attempting to use cast or dcast to make my data into the following format

id State contract.type Q1.2011 Q2.2011 ... Q2.2014

The source data is titled Med and is in the following format:

id is just a rownumber. I subset by NDC into two subsets, Med1 and Med2. I then use the following code to cast. If I cast with id included on the left hand side of the equation, I get some of the right numbers. For instance, AK has 120 in Q4.2014, but instead of putting the data in with one row for each state/rebate category pair, quarter by quarter, I have one good number per line and NAs for the rest of the time points. If I cast without id on the LHS, then I get an integer between 0 and 5 filled out for the entire sheet in every cell.

The output is

I also used the plyr id function to create a unique id for each combo of state and rebate combination as well, but I end up with the low integers again. Does anybody have any idea how to get the values of the medicaid column to go quarter by quarter for the unique id combos?

EDIT: Substituted original sample for dput sample recommended

0 投票
0 回答
79 浏览

java - 如何更改 IntelliJ 的“代码重新格式化”破坏实例化的方式?

当 IntelliJ 的代码重新格式化功能起作用时,它会将实例化表达式分解为不必要的更多行。

考虑这个表达式:

此表达式太长,无法容纳一行。IntelliJ 认为 100 个字符是最大行长。这个表达式有 136 个字符,不包括它所包含的方法和类的额外缩进。

使用 IntelliJ 的代码重新格式化我最终得到了这个:

我发现前两行看起来很奇怪,IntelliJ 将其重新格式化:

进入这个:

我能做什么,我应该更改哪些设置才能得到这样的结果?

注意:如果我再次尝试重新格式化,在我手动将 IntelliJ 坚持的两行改回一行后,IntelliJ 不会将其改回。

0 投票
3 回答
7833 浏览

java - 如何转换 javax.xml.datatype.Duration

我有来自服务器的javax.xml.datatype.Duration格式的响应。
这就是我得到的
旅行持续时间 = P2DT15H45M0S
,我希望它采用
所需格式 = 2 天 15 小时 45分钟
怎么做?
有没有办法从 javax.xml.datatype.Duration 转换为 String

谢谢你。

0 投票
1 回答
81 浏览

mysql - MySQL:将列值转换为带有总计的标题

我有一个结构如下的 MySQL 表“狗”:

所以这表示有 10 只 1 型狗的 aglevel 为 1,29 只 1 型狗的 ag 水平为 2 等等。

我想像这样重新格式化它:

所以在这里我们可以再次看到有 10 条类型为 1 的狗,其 aglevel 为 1。

我该怎么办?