在我的代码中,当选择特定的rowID时,Postgres表行中的所有信息都会被字符串化.
var jsonRes = result.message.rows;
document.getElementById('panel').innerHTML = '<pre>' + JSON.stringify(jsonRes[0], null, "\t") + '</pre>'
Run Code Online (Sandbox Code Playgroud)
结果看起来像这样:
{
"ogc_fid": 143667,
"relkey": 288007,
"acct": "000487000A0010000",
"recacs": "12.5495 AC",
"shape_star": 547131.567383,
"shape_stle": 3518.469618,
"objectid": 307755,
"zone_dist": "MU-3",
"pd_num": null,
"council_da": null,
"long_zone_": "MU-3",
"globalid": "{D5B006E8-716A-421F-A78A-2D71ED1DC118}",
"ord_num": null,
"notes": null,
"res_num": null,
"effectived": 1345766400000,
"shape.star": 629707.919922,
"shape.stle": 3917.657332,
"case_numbe": null,
"common_nam": null,
"districtus": null
}
Run Code Online (Sandbox Code Playgroud)
我是JS的新手,想知道是否有一种简单的方法可以完全排除包含空值的列 - 这个函数大致如下所示:
function hide(jsonObject) {
if (property === null) {
hide property
} else {
return str
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个jsonRes[0]包含需要根据条件删除的值的对象.以下工作原理用于删除null字符串化对象中的缺失值和等于零的值:
function replacer(key, value) {
// Filtering out properties
if (value === null || value === 0 || value === "") {
return undefined;
}
return value;
}
JSON.stringify(jsonRes[0], replacer, "\t")
Run Code Online (Sandbox Code Playgroud)
但是,当我使用该includes方法添加条件时,我收到一个错误:
function replacer(key, value) {
// Filtering out properties
if (value === null || value === 0 || value === "" || value.includes("$")) {
return undefined;
}
return value;
}
Uncaught TypeError: value.includes is not a function
Run Code Online (Sandbox Code Playgroud)
为什么会这样,是否有解决方法?
在我的rmarkdown文档中,我可以使用以下内容显示和隐藏代码 - 这会在每个代码块之前在文档的右侧创建一个方便的按钮:
output:
html_document:
code_folding: hide
Run Code Online (Sandbox Code Playgroud)
隐藏表格或数字是否有类似方便的方法?如果是这样,请提供参考,因为我找不到任何参考.否则,我们将不胜感激,谢谢!
我有一个推文列表,其中许多包含需要删除的表情符号.在R中这样做最有效的方法是什么?
我尝试了以下方法,它应该用"空白"替换以"\"开头的所有单词,但是我收到此错误
some_tweets <- gsub("\\\w+ *", "", some_tweets)
Error: '\w' is an unrecognized escape in character string starting ""\\\w"
Run Code Online (Sandbox Code Playgroud)
以下是数据示例:
> head(some_tweets)
[1] "??? ???? ??????? ????? \U0001f625\U0001f625\U0001f625"
[2] "?????? ?????????? \U0001f913\U0001f913\U0001f913"
[3] "???? ????? ?????? ??????? \U0001f602\U0001f602\U0001f602\U0001f602"
[4] "???"
[5] "RT : ?????????? ??????.. ~ ?????"
[6] "?????? ??????? ???? ??????????? ????????? ????????? ??????? ????????? \U0001f608\U0001f608\U0001f608"
> dput(head(some_tweets))
c("??? ???? ??????? ????? \U0001f625\U0001f625\U0001f625",
"?????? ?????????? \U0001f913\U0001f913\U0001f913",
"???? ????? ?????? ??????? \U0001f602\U0001f602\U0001f602\U0001f602",
"???", "RT : ?????????? ??????.. ~ ?????",
"?????? …Run Code Online (Sandbox Code Playgroud) 我找到了以下代码来显示和隐藏Mapbox GL中的图层:
https://www.mapbox.com/mapbox-gl-js/example/toggle-layers/
这是有帮助的,但是,我只有一个带有所有必要数据的.geojson图层(折线),不需要创建单独的图层.
我想做一个完全相同的功能,能够在地图菜单中显示和隐藏一个图层的功能.共有12种不同的要素类型,包含在名为"类型"的列中.我想打开和关闭类型,就像在示例中一样.
在JS中有一个简单的方法来做到这一点set.Filter吗?
https://github.com/mapbox/mapbox-gl-js/blob/e9386d2880cc2c33e9a5a16b9bcb58834026a078/js/ui/map.js#L559-L562
我一直无法提出解决方案.
我的.geojson图层在这里:https://iskandarblue.github.io/mapbox/data/simplify_prototype.geojson
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title></title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.15.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.15.0/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<style>
#menu {
background: #fff;
position: absolute;
z-index: 1;
top: 10px;
right: 10px;
border-radius: 3px;
width: 120px;
border: 1px solid rgba(0,0,0,0.4);
font-family: 'Open Sans', sans-serif;
}
#menu a {
font-size: 13px;
color: #404040; …Run Code Online (Sandbox Code Playgroud) 我有两列PosixLT时间没有NA值,但NA值会在检查时显示
> sum(is.na(check$start))
[1] 19
> sum(is.na(check$end))
[1] 23
Run Code Online (Sandbox Code Playgroud)
数据存在于单元格中,为什么会发生这种情况呢?我听说PosixLT会发生这种情况,但即使我将其转换为posixCT,也会有非常奇怪的行为.如何解决这个问题呢?
> as.POSIXct(check$start, format = "%Y-%m-%d %H:%M:%S", tz = "CST6CDT")
[1] NA "2014-03-09 01:35:01 CST" NA "2014-03-09 01:53:30 CST" NA
[6] NA NA NA NA "2014-03-09 04:17:11 CDT"
[11] NA NA "2015-03-08 01:54:43 CST" NA NA
[16] NA NA NA NA NA
[21] NA NA NA
> dput(check)
structure(list(start = structure(list(sec = c(24, 1, 27, 30,
8, 21, 40, 9, 43, 11, 31, 43, 43, 55, 39, 54, 41, 19, 2, …Run Code Online (Sandbox Code Playgroud) 我有一个重复序列的数据集TRUE,我希望根据某些条件标记 - 依据id序列的增量值.A FALSE打破TRUEs 的序列,并且第一个FALSE打破任何给定序列的序列TRUE应包括在该序列中.FALSEs之间TRUE的连续s 是无关紧要的,标记为0.
例如:
> test
id logical sequence
1 1 TRUE 1
2 1 TRUE 1
3 1 FALSE 1
4 1 TRUE 2
5 1 TRUE 2
6 1 FALSE 2
7 1 TRUE 3
8 2 TRUE 1
9 2 TRUE 1
10 2 TRUE 1
11 2 FALSE 1
12 2 TRUE 2
13 2 TRUE 2
14 …Run Code Online (Sandbox Code Playgroud) 对于数据集test,我的目标是找出有多少独特用户在一个时期内从一个时期转移到下一个时期.
> test
user_id period
1 1 1
2 5 1
3 1 1
4 3 1
5 4 1
6 2 2
7 3 2
8 2 2
9 3 2
10 1 2
11 5 3
12 5 3
13 2 3
14 1 3
15 4 3
16 5 4
17 5 4
18 5 4
19 4 4
20 3 4
Run Code Online (Sandbox Code Playgroud)
例如,在第一个时期,有四个唯一用户(1,3,4和5),其中两个在第二个时期有效.因此保留率为0.5.在第二个时期,有三个独特的用户,其中两个在第三个时期有效,因此保留率为0.666,依此类推.如何找到下一期间活跃的唯一身份用户的百分比?任何建议,将不胜感激.
输出如下:
> output
period retention
1 1 NA
2 2 0.500
3 …Run Code Online (Sandbox Code Playgroud) 我正在尝试调整我的Rmarkdown文档中的饼图,以使其跨越页面的宽度,或者至少变得足够宽以适合所有标签。
我已经尝试了所有方法- 用和调整figure.height和figure.width,边距,但是似乎没有任何效果。要么馅饼本身变小,要么标签被切掉。我希望带有清晰可见标签的馅饼尽可能大,但是每次渲染小馅饼和微小标签时。par(mar)par(oma)
是否至少有一种解决方法,以使标签不被切除(或可以与相邻图表重叠)?任何建议,将不胜感激。
```{r, figure.align = "center", figure.height = 10, figure.width = 12}
par(mfrow=c(1,3), cex.axis=1.5, cex.lab=1.5)
par(mar = c(4,2,4,2))
par(oma = c(3, 3, 3, 3))
pie(a, labels = lbls, font = 2, col = c("tomato", "white"), cex=2)
pie(b, lbls2, font = 2, col = c("tomato", "white"), cex=2)
mtext(side=3, text="Plan Breakdown: Top 20% of Users")
pie(c, lbls3, font = 2, col = c("tomato", "white"))
Run Code Online (Sandbox Code Playgroud)
我有一个包含许多列的宽表,我希望能够在 R-markdown 中使用水平滚动条整齐地显示这些列。我已阅读文档并尝试了以下操作
```{css}
pre code, pre, code {
overflow-x: scroll !important;
}
```
Run Code Online (Sandbox Code Playgroud)
以及options(width = 1000)在代码块中设置。这两种方法都失败了。
kable(mat)) 显示彼此堆叠的行名和列名,但我想通过 x-overflow 避免这种情况
任何建议将不胜感激。这是完整的数据集:
> dput(mat)
structure(list(`Jul 2016` = c(0.108624566189299, 1.76516237793691,
0.24654630490587, 0.336005341665282, 1.00201353799076, 1.36940398901225,
3.66411692441857, 0.927558916609414, 0.691046979743987, 0.450146262999624,
0.917686009737563, 0.140224124770612, 0.843074107500625, 1.05518907118113
), `Aug 2016` = c(0.495219146367162, 0.391441250685602, 1.54749462052876,
0.173654376994818, 0.633756110444665, 0.631372984033078, 0.18316258961296,
0.182683125603944, 3.05005361690094, 3.94560365916646, 1.23740167125376,
0.104842279106379, 1.19900375879825, 0.885420372667623), `Sep 2016` = c(0.233641386257531,
0.0033428730592414, 0.750113554504904, 3.29350166751032, 0.321632610633969,
0.147915420588106, 0.588389918208122, 0.448350375518203, 0.11338227847591,
0.183331309817731, 0.503199412953109, 0.171937711299566, 1.95316866590622,
0.104802044216859), `Oct …Run Code Online (Sandbox Code Playgroud) r ×7
javascript ×3
r-markdown ×3
dplyr ×2
data.table ×1
datetime ×1
figure ×1
json ×1
knitr ×1
mapbox ×1
mapbox-gl ×1
pie-chart ×1
posixct ×1
regex ×1
retention ×1
stringify ×1
substitution ×1
twitter ×1
unicode ×1