gpt4 book ai didi

r - 冒号等于 R 中的运算符?新语法?

转载 作者:行者123 更新时间:2023-12-04 02:04:51 27 4
gpt4 key购买 nike

阅读时http://ggvis.rstudio.com/interactivity.html ,我注意到代码中有 := 洒在其中。我认为这是一种为函数提供参数的新方法?究竟是什么?

mtcars %>%
ggvis(~wt, ~mpg, size := input_slider(10, 1000)) %>%
layer_points(fill := "red") %>%
layer_points(stroke := "black", fill := NA)

最佳答案

在这种情况下,:=只是 ggvis 用于分配固定值的语法;相比之下,=这里将用于分配变量值。正如您在代码示例中可能已经注意到的那样,在右侧,只有“red”或 NA 这样的值,因此 :=是在此上下文中使用的正确运算符。例如,如果您希望“size”依赖于“mpg”列,您可以编写 size = mpg , 使用通常的等号。

我承认我对:=不够熟悉说是否有其他包也采用了这个操作符。

From http://ggvis.rstudio.com/properties-scales.html (see for further examples and information):

"The props() function uses the = operator for mapping (scaled), and the := operator for setting (unscaled). It also uses the ~ operator to indicate that an expression should be evaluated in the data (and in ggvis, the data can change); without the ~ operator, the expression is evaluated immediately in the current environment. Generally speaking, you’ll want to use ~ for variables in the data, and not use it for constant values."

关于r - 冒号等于 R 中的运算符?新语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32077483/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com