我想为每个条目创建一个带有项目符号的输出
数据
我的数据框中只有一行:
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
实际结果
我离我想要的还很接近。但是,R不仅会打印所需部分,还会在后面添加所有列的列表。因此输出结果如下:
* 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
除了能够正常工作的解决方案,我非常希望有人能够给我提示这里发生了什么。
x
,它既没有任何有意义的内容,也不需要它。 - Jan