Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of this trailing comma in R?

Tags:

r

Why does the first line work and the 2nd not? I can't find the reason in the documentation on how to use which to select data although by chance I figured out I needed a comma.

sigData <- data[which(abs(data$wc2) > 3*wc2_sd),]


sigData <- data[which(abs(data$wc2) > 3*wc2_sd)]
like image 310
SwimBikeRun Avatar asked Jun 11 '13 19:06

SwimBikeRun


People also ask

What are commas used for in R?

A comma separator in number will give clarity of a number, and we can count easily when a number is separated by a comma.

What is trailing comma Python?

In Python, a tuple is actually created by the comma symbol, not by the parentheses. Unfortunately, one can actually create a tuple by misplacing a trailing comma, which can lead to potential weird bugs in your code. You should always use parentheses explicitly for creating a tuple.

Does Python allow trailing comma?

Python Language Dictionary The trailing comma Like lists and tuples, you can include a trailing comma in your dictionary. PEP 8 dictates that you should leave a space between the trailing comma and the closing brace.


1 Answers

The trailing comma in the first line indicates you're subsetting by rows (remember [ is a function that means subset)

The lack of a trailing comma in the second line indicates you're subsetting by columns. The second row would be equivalent to using a leading comma inside the brackets.

sigData <- data[, which(abs(data$wc2) > 3*wc2_sd)]
like image 118
Justin Avatar answered Nov 15 '22 19:11

Justin