我有一个 R markdown 文档,它是使用闪亮的应用程序创建的,保存为 HTML。我在输出的右上角插入了一个徽标,这是使用以下代码完成的:
<script>
$(document).ready(function() {
$head = $('#header');
$head.prepend('<img src=\"FILEPATH/logo.png\" style=\"float: right;padding-right:10px;height:125px;width:250px\"/>')
});
</script>
Run Code Online (Sandbox Code Playgroud)
但是,当我保存 HTML 输出并共享输出时,用户当然看不到徽标,因为代码试图找到在他们的计算机上不存在的文件路径。
所以,我的问题是 - 有没有办法在不使用文件路径的情况下在输出中包含徽标?理想情况下,我不想将图像上传到网络,并将源更改为网址。
我真的不知道怎么说这个问题所以很容易理解,所以请耐心等待.
我有一个2列矩阵,需要根据另一个矩阵修改第1列中的值h.
例如,h可能看起来像这样:h <- c(11,10,10,8,12)
我的数据矩阵如下所示:
[1,] 0 0
[2,] 0 0
[3,] 0 26
[4,] 0 44
[5,] 0 0
[6,] 0 65
[7,] 0 0
[8,] 0 0
[9,] 0 0
[10,] 0 28
[11,] 0 25
[12,] 0 0
[13,] 0 81
[14,] 0 0
[15,] 0 0 ...
Run Code Online (Sandbox Code Playgroud)
等等...
我需要根据向量中的项目编号重命名零列h.所以我需要将行1:11标记为1,12:21标记为2,22:31标记为3等,如下所示:
[1,] 1 0
[2,] 1 0
[3,] 1 26
[4,] 1 44
[5,] 1 0
[6,] 1 65
[7,] …Run Code Online (Sandbox Code Playgroud) 我有一个矩阵,看起来有点像这样:
Date Time Data
15000 04/09/2014 05:45:00 0.908
15001 04/09/2014 06:00:00 0.888
15002 04/09/2014 06:15:00 0.976
15003 04/09/2014 06:30:00 1.632
15004 04/09/2014 06:45:00 1.648
15005 04/09/2014 07:00:00 1.164
15006 04/09/2014 07:15:00 0.568
15007 04/09/2014 07:30:00 1.020
15008 04/09/2014 07:45:00 1.052
15009 04/09/2014 08:00:00 0.920
15010 04/09/2014 08:15:00 0.656
15011 04/09/2014 08:30:00 1.172
15012 04/09/2014 08:45:00 1.000
15013 04/09/2014 09:00:00 1.420
15014 04/09/2014 09:15:00 0.936
15015 04/09/2014 09:30:00 0.996
15016 04/09/2014 09:45:00 1.100
15017 04/09/2014 10:00:00 0.492
Run Code Online (Sandbox Code Playgroud)
它包含一年的数据,每天有 96 行(从 00:00 …
我有一个包含一Reference列的数据框。这是一个10位数字,可以从零开始。导入R时,前导零消失,我想重新添加。
我尝试使用sprintf和formatC,但是每个都有不同的问题。
DF=data.frame(Reference=c(102030405,2567894562,235648759), Data=c(10,20,30))
Run Code Online (Sandbox Code Playgroud)
我得到的输出如下:
> sprintf('%010d', DF$Reference)
[1] "0102030405" " NA" "0235648759"
Warning message:
In sprintf("%010d", DF$Reference) : NAs introduced by coercion
> formatC(DF$Reference, width=10, flag="0")
[1] "001.02e+08" "02.568e+09" "02.356e+08"
Run Code Online (Sandbox Code Playgroud)
当数字已经有10位数字时,第一个输出给出NA,第二个输出以标准格式存储结果。
我需要的是:
[1] 0102030405 2567894562 0235648759
Run Code Online (Sandbox Code Playgroud) 我有一个数据列表,我希望将其转换为矩阵.我知道我的矩阵需要的确切大小,但数据并没有完全填满它.例如,对于长度为95的向量,我想将其转换为25*4矩阵.使用矩阵命令不起作用,因为值的数量不适合矩阵,所以我需要一种方法用NA填充它,并逐行填充矩阵.
矩阵的大小在每种情况下都是已知的,但是从一组数据到下一组数据不一致,因此理想情况下,如果数据不可用,将会有一个自动用NA填充矩阵的函数.
示例代码:
example=c(20.28671, 20.28544, 20.28416, 20.28288, 20.28161, 20.28033, 20.27906, 20.27778, 20.27651, 20.27523, 20.27396, 20.27268, 20.27141,
20.27013, 20.26885, 20.26758, 20.26533, 20.26308, 20.26083, 20.25857, 20.25632, 20.25407, 20.25182, 20.24957, 20.24732, 20.24507,
20.24282, 20.24057, 20.23832, 20.23606, 20.23381, 20.22787, 20.22193, 20.21598, 20.21004, 20.20410, 20.19816, 20.19221, 20.18627,
20.18033, 20.17438, 20.16844, 20.16250, 20.15656, 20.15061, 20.14467, 20.13527, 20.12587, 20.11646, 20.10706, 20.09766, 20.08826,
20.07886, 20.06946, 20.06005, 20.05065, 20.04125, 20.03185, 20.02245, 20.01305, 20.00364, 20.00369, 20.00374, 20.00378, 20.00383,
20.00388, 20.00392, 20.00397, 20.00401, 20.00406, 20.00411, 20.00415, 20.00420, 20.00425, 20.00429, 20.00434, 20.01107, …Run Code Online (Sandbox Code Playgroud) 我想将回归线方程和 r 平方值添加到我的ggplot2散点图中。
我发现了一个类似的问题,它给出了下面的代码,但是当我通过截距强制回归时它不起作用:
library(devtools)
source_gist("524eade46135f6348140")
df = data.frame(x = c(1:100))
df$y = 2 + 5 * df$x + rnorm(100, sd = 40)
ggplot(data = df, aes(x = x, y = y, label=y)) +
stat_smooth_func(geom="text",method="lm",hjust=0,parse=TRUE, formula=y~x-1) +
geom_smooth(method="lm",se=FALSE, formula=y~x-1) +
geom_point()
Run Code Online (Sandbox Code Playgroud)
通过添加formula=y~x-1,显示的文本显示系数为截距,截距为NA。有没有办法解决这个问题?
r ×6
dataframe ×2
matrix ×2
average ×1
datetime ×1
for-loop ×1
ggplot2 ×1
html ×1
image ×1
leading-zero ×1
lm ×1
loops ×1
r-markdown ×1
read.csv ×1
regression ×1
sequential ×1
subset ×1
text ×1
zero ×1