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)]
A comma separator in number will give clarity of a number, and we can count easily when a number is separated by a comma.
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.
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.
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)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With