R Plyr包中变量(即“变量”)之前点的目的是什么?

时间:2022-04-11 09:15:57

What is purpose of dot before variables (i.e. "variables") in the R Plyr package?

R Plyr包中变量(即“变量”)之前点的目的是什么?

for instance, from the R help file:

例如,从R帮助文件:

ddply(.data, .variables, .fun = NULL, ...,
    .progress = "none", .drop = TRUE, .parallel = FALSE)

Any assistance would be greatly appreciated

任何帮助将不胜感激

2 个解决方案

#1


11  

There may be two things going on that are confusing you.

可能有两件事让你感到困惑。

One is the . function in the 'plyr' package. The . function allows you to use a variable as a link rather than referring to the value(s) the variable contains. For instance, in some functions, we want to refer to the object x rather than the value(s) stored in x. In the 'base' package, there is no easy, concise way of doing this, so we use the 'plyr' package to say .(x). The 'plyr' functions themselves use this a lot like so:

一个是。功能在'plyr'包中。这个。函数允许您将变量用作链接,而不是引用变量包含的值。例如,在某些函数中,我们想要引用对象x而不是x中存储的值。在“基础”包中,没有简单,简洁的方法,所以我们使用'plyr'包来说。(x)。 'plyr'函数本身就像这样使用它:

ddply(data, .(row_1), summarize, total=sum(row_1))

If we didn't use the . function, 'ddply' would complain, because 'row_1' contains many values, when we really just want to refer to the object.

如果我们没有使用。函数'ddply'会抱怨,因为'row_1'包含很多值,当我们真的只想引用该对象时。

The other "." in action here is the way people use it as a character in the function arguments' names. I'm not sure what the origin is, but a lot of people seem to do it just to highlight which variables are function arguments and which variables are only part of the function's internal code. The "." is just another character, in this case.

另一个 ”。”这里的行为是人们将它用作函数参数名称中的字符的方式。我不确定原点是什么,但是很多人似乎只是为了突出显示哪些变量是函数参数以及哪些变量只是函数内部代码的一部分。 “。”在这种情况下,只是另一个角色。

#2


6  

From http://www.jstatsoft.org/v40/i01

来自http://www.jstatsoft.org/v40/i01

Note that all arguments start with . This prevents name *es with the arguments of the processing function, and helps to visually delineate arguments that control the repetition from arguments that control the individual steps. Some functions in base R use all uppercase argument names for this purpose, but I think this method is easier to type and read.

请注意,所有参数都以。这可以防止与处理函数的参数发生名称冲突,并有助于直观地描述控制来自控制各个步骤的参数的重复的参数。基本R中的一些函数为此目的使用所有大写参数名称,但我认为这种方法更容易键入和读取。

#1


11  

There may be two things going on that are confusing you.

可能有两件事让你感到困惑。

One is the . function in the 'plyr' package. The . function allows you to use a variable as a link rather than referring to the value(s) the variable contains. For instance, in some functions, we want to refer to the object x rather than the value(s) stored in x. In the 'base' package, there is no easy, concise way of doing this, so we use the 'plyr' package to say .(x). The 'plyr' functions themselves use this a lot like so:

一个是。功能在'plyr'包中。这个。函数允许您将变量用作链接,而不是引用变量包含的值。例如,在某些函数中,我们想要引用对象x而不是x中存储的值。在“基础”包中,没有简单,简洁的方法,所以我们使用'plyr'包来说。(x)。 'plyr'函数本身就像这样使用它:

ddply(data, .(row_1), summarize, total=sum(row_1))

If we didn't use the . function, 'ddply' would complain, because 'row_1' contains many values, when we really just want to refer to the object.

如果我们没有使用。函数'ddply'会抱怨,因为'row_1'包含很多值,当我们真的只想引用该对象时。

The other "." in action here is the way people use it as a character in the function arguments' names. I'm not sure what the origin is, but a lot of people seem to do it just to highlight which variables are function arguments and which variables are only part of the function's internal code. The "." is just another character, in this case.

另一个 ”。”这里的行为是人们将它用作函数参数名称中的字符的方式。我不确定原点是什么,但是很多人似乎只是为了突出显示哪些变量是函数参数以及哪些变量只是函数内部代码的一部分。 “。”在这种情况下,只是另一个角色。

#2


6  

From http://www.jstatsoft.org/v40/i01

来自http://www.jstatsoft.org/v40/i01

Note that all arguments start with . This prevents name *es with the arguments of the processing function, and helps to visually delineate arguments that control the repetition from arguments that control the individual steps. Some functions in base R use all uppercase argument names for this purpose, but I think this method is easier to type and read.

请注意,所有参数都以。这可以防止与处理函数的参数发生名称冲突,并有助于直观地描述控制来自控制各个步骤的参数的重复的参数。基本R中的一些函数为此目的使用所有大写参数名称,但我认为这种方法更容易键入和读取。