- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这个问题在这里已经有了答案:
How to suppress part of the output from `lapply()`?
(2 个回答)
去年关闭。
我想为每个条目创建一个带有项目符号的输出
数据
我的数据框中有一行(并且只有一行):
structure(list(Dimensions = 2L, Continuity = structure(2L, .Label = c("",
"continuous"), class = "factor"), Differentiability = structure(2L, .Label = c("",
"differentiable", "non-differentiable"), class = "factor"), Convexity = structure(2L, .Label = c("",
"convex", "non-convex"), class = "factor"), Modality = structure(3L, .Label = c("",
"multimodal", "unimodal"), class = "factor"), Separability = structure(2L, .Label = c("",
"non-separable", "non-separable,", "separable"), class = "factor"),
Scalability = structure(2L, .Label = c("", "non-scalable",
"scalable"), class = "factor"), Parametric = FALSE, Random = FALSE), row.names = 2L, class = "data.frame")
mapply(function(x, y) cat("* ", y, ": ", as.character(x), "\n"), Descr, names(Descr))
* Dimensions : 2
* Continuity : continuous
* Differentiability : differentiable
* Convexity : convex
* Modality : unimodal
* Separability : non-separable
* Scalability : non-scalable
* Parametric : FALSE
* Random : FALSE
* Dimensions : 2
* Continuity : continuous
* Differentiability : differentiable
* Convexity : convex
* Modality : unimodal
* Separability : non-separable
* Scalability : non-scalable
* Parametric : FALSE
* Random : FALSE
$Dimensions
NULL
$Continuity
NULL
$Differentiability
NULL
$Convexity
NULL
$Modality
NULL
$Separability
NULL
$Scalability
NULL
$Parametric
NULL
$Random
NULL
最佳答案
*apply
R 中的函数总是有输出。
解决此问题的一种方法是使用 invisible
调用它们。 :
invisible(mapply(function(x, y) cat("* ", y, ": ", as.character(x), "\n"), Descr, names(Descr)))
* Dimensions : 2
* Continuity : continuous
* Differentiability : differentiable
* Convexity : convex
* Modality : unimodal
* Separability : non-separable
* Scalability : non-scalable
* Parametric : FALSE
* Random : FALSE
purrr
包有
walk
正是出于这个原因的一组函数:
library(purrr)
walk2(Descr,names(Descr), function(x, y) cat("* ", y, ": ", as.character(x), "\n"))
* Dimensions : 2
* Continuity : continuous
* Differentiability : differentiable
* Convexity : convex
* Modality : unimodal
* Separability : non-separable
* Scalability : non-scalable
* Parametric : FALSE
* Random : FALSE
关于r - 使用“mapply”创建输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61822263/
我试图找出有关 .mapply 的信息,但没有找到任何好的解释。那么谁能解释一下 mapply 和 .mapply 之间的区别? 例子: 为什么.mapply(cbind,mylist,NULL)有效
我编写了一个函数,可以将基数为 10 的数字转换为另一个基数(我只对基数 2 - 9 感兴趣)。我当前将基数 10 转换为基数 2 的函数如下所示: cb2 0 ){ a 0 ){
这个问题在这里已经有了答案: Force mapply to return a list? (2 个回答) 7年前关闭。 我有一个函数,我正在使用 mapply 跨数据框或矩阵 (df) 列表应用该函
我正在尝试使用 mapply 来组合两个列表(A 和 B)。每个元素都是一个数据框。 我正在尝试将 A 中的数据帧绑定(bind)到 B 中的相应数据帧。以下返回我想要的组合 1: num = 10
使用基础 R,我想在嵌套列表上使用 mapply 函数。例如,在下面的代码中,我试图从嵌套列表的每个元素中删除字母“a”。我想用一行代码替换最后两行。 mylist <- list( list
我正在尝试编写一个在涉及两个列表和一个数据框的 mapply 中使用的函数。我想挑选出由两个列表(行和列)索引的几个数据子集。这是我想在循环中执行的操作的示例,以及我对该函数的尝试: #simulat
我希望计算矩阵的每一列(或行)中相邻值的平均值(例如 [1,1] 和 [2,1]、[2,1] 和 [3,1]、[3, 1] 和 [4,1]) 并将其应用于所有列。 我尝试使用 mapply 函数(以避
我有一个 R 函数可以计算两个向量的汉明距离: Hamming = function(x,y){ get_dist = sum(x != y, na.rm=TRUE) return(get_dist)
使用以下两个数据框 > d1 keystr keynum 1 abc 5 2 def 2 3 def 7 4 abc 3 > d2
我正在使用 mapply() 将列表中的元素保存在单独的文件中。例如。 file.names <- c('~/a.RData', '~/b.RData') data.list <- list(foo
我正在尝试创建一个用于创建图形的 data.frame。我有一个函数和两个向量,我想用作两个输入。这有点简化,但基本上我所拥有的是: relGPA expGPA2$fn str(expGPA2)
我正在尝试使用 mapply 将月份添加到数据框 a 和 b 列中的当前日期。这是创建示例数据框的代码: library(lubridate) a <- as.Date(c("2012-01-11",
我想在数据表中做一个看似简单的 mapply 应用。我想将一系列数据表列乘以另一列中的值。这是我的功能。 y 是与其他列中的值相乘的单列。 xIn 是一个列名来做这个操作。 f.xRatio <- f
我可以使用以下 MyFun(用户定义)函数来模拟观察。但是无法弄清楚如何在函数返回输出列表时使用 replicate 函数重复此函数。 MyFun <- function(nSim, Size, Pr
我发了一个 answer使用 dplyr 回答问题和 tidyr .基于 this comment我用过 Map建立答案。 接下来我尝试使用 base R工具仅用于回答相同的问题,但这并没有按预期工作
我想在 mapply 中传递一个函数名作为参数: f2 <- function(a, b) a + b^2 f <- function(a, b, func) func(a, b) f(1, 3, f
我有一个带有单列“条款”的data.frame。它可以包含多个单词的字符串。每个词至少包含两个词或更多,没有上限。 从“条款”这一列中,我想提取最后一个单词并将其存储在一个新的“最后”列中。 # lo
我有一个列表“temp”,它等于 [[1]] [1] 8 0 3 [[2]] [1] 6 4 0 [[3]] [1] 0 5 0 和一个向量 vec = c(1,2,3,4,5,6,7,8,9) .我
我有一个函数,它接受一个 Date 对象并返回一个。但是,当我使用 mapply 函数将该函数应用于 data.frame 列时,我遇到了问题:我没有按预期返回日期对象,而是返回数字。知道如何将它们转
所以我知道 mapply 将按元素顺序遍历一个数组(或一系列数组)——我想知道是否有办法阻止它对某些参数执行此操作……。让我进一步解释 我有一组数据点,带有 X 和 Y 坐标……X1 X2 ……Xn
我是一名优秀的程序员,十分优秀!