0

I have this code, from Julian Farawy's linear models book:

round(cor(seatpos[,-9]),2)

I am unsure what [,-9],2 is doing - could someone please assist?

lmo
  • 37,904
  • 9
  • 56
  • 69
K-Q
  • 133
  • 8
  • Calculate the correlation of all columns in `seatpos` but do not include the nineth column. Then round with 2 decimal places. See `?round` – KoenV Aug 24 '17 at 15:03
  • Maybe try changing those values to see how the results differ. – MrFlick Aug 24 '17 at 15:08

1 Answers1

3

When you are learning new stuff nested functions can be difficult. This same computation could be accomplished in steps, which might be easier for you to see what KeonV and MrFlick are suggesting.

Here is an alternative way of doing this the same functions but easier steps to differentiate with simple explanations.

sub_seatpos<- seatpos[,-9]

this says take a subset of all rows and all columns EXCEPT column number nine and save it into sub_seatpos (this subseting was done in the initial code, but not saved into a new variable. This just makes seeing how each step works easier).

and reflects the bold portion below

round(cor(seatpos[,-9]),2)

 cor_seatpos <- cor(sub_seatpos)

This takes the correlation for sub_seatpos and saves them into a variable named cor_seatpos. It reflects the part listed below in bold

round( cor( seatpos[,-9] ),2)

The final step just says round the correlation to 2 decimal places and would look like this in separate lines of code.

round(cor_seatpos, 2)

it is reflected in the bold below

round( cor(seatpos[,-9]),2)

What makes this confusing is that all of the functions are nested. As you become more proficient, this becomes less of a difficulty to read. But it can be confusing with new functions.

sconfluentus
  • 4,693
  • 1
  • 21
  • 40