假设我有一堆函数,每个函数都有类似MyFunction.1等等.我想将这些函数传递给另一个函数,它打印出一个小报告.理想情况下,我希望能够标记报告的各个部分,通过这些部分使用函数来生成结果.
那么有什么好方法可以将预定义函数的名称作为字符串获取吗?
我最近开始使用 are,我想扩展我的数据矩阵。我在这里找到了一种方法来在两点之间缩放一个系列
x <- data.frame(step = c(1,2,3,4,5,6,7,8,9,10))
normalized <- (x-min(x))/(max(x)-min(x))
Run Code Online (Sandbox Code Playgroud)
由于我的数据由几列组成,因此我只想使用建议的函数对某些列进行规范化。
normalized <- function(x) (x- min(x))/(max(x) - min(x))
x[] <- lapply(x, normalized)
Run Code Online (Sandbox Code Playgroud)
此外,我意识到我的数据集中的某些数据点等于 0,因此所提供的公式不再适用。我在这里添加了一个扩展建议:将r 数据帧缩放到 0-1 与 NA 值
normalized <- function(x, ...) {(x - min(x, ...)) / (max(x, ...) - min(x, ...))}
Run Code Online (Sandbox Code Playgroud)
但我不明白我必须如何编码。例如,我想让第 4、5、6 和 10 列标准化,但我想让其余的列保持在数据集中的状态?我在第 4 列中尝试过:
data <- lapply(data[,4],normalized,na.rm= TRUE)
Run Code Online (Sandbox Code Playgroud)
但它没有用(而不是数据框,结果是一个列表:-(...),有谁知道我如何解决它?
非常感谢!
我在另一个函数中有一个函数,如下所示:
func2 <- function(x=1) {ko+x+1}
func3= function(l=1){
ko=2
func2(2)+l
}
func3(1)
Run Code Online (Sandbox Code Playgroud)
它显示错误:Error in func2(2) : object 'ko' not found。基本上我想使用ko在调用func2之前不会定义的对象。func3有什么解决办法吗?
所以有一种情况:
数据帧:
dat <- data.frame(colA = rep(c(0,1,0), c(6,1,8)),
colB = rep(c(1,0,1,0), c(1,4,1,9)),
colC = rep(c(0,1,0), c(9,1,5)),
colD = rep(c(0,1,0), c(8,1,6)),
colE = rep(0, 15),
color = rep(c("blue","red","yellow"), each=5),
colorId = rep(c(22,40,35), each=5))
colA colB colC colD colE color colorId
0 1 0 0 0 Blue 22
0 0 0 0 0 Blue 22
0 0 0 0 0 Blue 22
0 0 0 0 0 Blue 22
0 0 0 0 0 Blue 22
0 1 0 0 0 Red …Run Code Online (Sandbox Code Playgroud) 我想在其中创建一个带有居中的传单小部件的html文档.
---
title: "Exemple"
author: "Antoine Bichat"
date: "31/08/2018"
output: html_document
---
```{r leaflet, fig.align="center"}
library(leaflet)
leaflet() %>%
addTiles() %>%
addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")
```
Run Code Online (Sandbox Code Playgroud)
第一个想法fig.align="center"不起作用.
我找到了这个问题,并根据我的情况进行了调整:
<style>
/* resize the widget container */
.leaflet {
width: 80% !important;
}
/* center the widget */
div.leaflet-control-container {
margin: auto !important;
}
</style>
Run Code Online (Sandbox Code Playgroud)
但如果我不想拥有out.width100%(而且我不想),它就不起作用.
或许我做错了......其实我更喜欢100%R/ Rmarkdown解决方案,但我对一切都开放:)
我有以下格式的数据。向量的第一个元素是指标题,向量的第二个到底部是指与标题相对应的值。我想将数据放入表格/结构化格式(或带有标题和值的数据框)中。
k <- c("Afv.dato : Type Termin lalt Betalt pa termin Terminsbelgb", "13-09-2019 opkrzvning 11-09-2019 4.067,11",
"18-10-2019 indbetaling 4.067,00 11-09-2019 4.067,00", "11-12-2019 opkrzvning 11-12-2019 9.176,00" ,
"18-12-2019 indbetaling 9.176,11 11-09-2019 0,11", "11-12-2019 9.176,00", "11-03-2020 opkreevning 11-03-2020 9.176,00",
"02-03-2020 indbetaling 9.176,00 11-03-2020 9.176,00", "11-06-2020 opkraevning 11-06-2020 9.176,00",
"18-05-2020 indbetaling 9,176,00 11-06-2020 9.176,00"
)
Run Code Online (Sandbox Code Playgroud)
我想禁用区域设置失败警告以显示在命令行上。
在系统(aix)中,可用的语言环境有 C、POSIX、en_US.8859-15、en_US.ISO8859-1、en_US
设置的语言为“EN_US”(export $LANG=EN_US),该语言在上面的列表中不可用。由于执行以下命令会引发警告。如果从上面的列表中设置语言(export $LANG=en_US),则工作正常。
# perl -X -e "print 'hello'"
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LC_ALL = (unset),
LC__FASTMSG = "true",
LANG = "EN_US"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C")
Run Code Online (Sandbox Code Playgroud)
我在 perl 脚本中保留了相同的命令,并且它抛出了相同的警告。我也用过$SIG(__WARN__),但是上面的警告在这里没有被捕获。但是与未声明的变量等相关的其他警告正在被捕获。一种解决方案是安装我知道的不可用的区域设置,但希望禁用它,因为我的代码具有选择其他语言消息的逻辑。
那么如何禁用屏幕上的这些警告呢?