06.09.2021 Views

Learning Statistics with R - A tutorial for psychology students and other beginners, 2018a

Learning Statistics with R - A tutorial for psychology students and other beginners, 2018a

Learning Statistics with R - A tutorial for psychology students and other beginners, 2018a

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

under the influence of alcohol, caffeine etc).<br />

Because of the fact that the variable naming scheme here is so in<strong>for</strong>mative, it’s quite possible to<br />

reshape the data frame <strong>with</strong>out any additional input from the user. For example, in this particular case,<br />

you could just type the following:<br />

> wideToLong( drugs )<br />

id gender <strong>with</strong>in WMC RT<br />

1 1 female alcohol 3.7 488<br />

2 2 female alcohol 6.4 607<br />

3 3 female alcohol 4.6 643<br />

4 4 male alcohol 6.4 684<br />

BLAH BLAH BLAH<br />

This is pretty good, actually. The only think it has gotten wrong here is that it doesn’t know what name<br />

to assign to the <strong>with</strong>in-subject factor, so instaed of calling it something sensible like drug, it has use<br />

the unimaginative name <strong>with</strong>in. If you want to ensure that the wideToLong() function applies a sensible<br />

name, you have to specify the <strong>with</strong>in argument, which is just a character string that specifies the name<br />

of the <strong>with</strong>in-subject factor. So when I used this comm<strong>and</strong> earlier,<br />

> drugs.2 drugs.2 longToWide( data=drugs.2, <strong>for</strong>mula= WMC+RT ~ drug )<br />

id gender WMC_alcohol RT_alcohol WMC_caffeine RT_caffeine WMC_no.drug RT_no.drug<br />

1 1 female 3.7 488 3.7 236 3.9 371<br />

2 2 female 6.4 607 7.3 376 7.9 349<br />

18 This limitation is deliberate, by the way: if you’re getting to the point where you want to do something more complicated,<br />

you should probably start learning how to use reshape(), cast() <strong>and</strong> melt() or some of <strong>other</strong> the more advanced tools. The<br />

wideToLong() <strong>and</strong> longToWide() functions are included only to help you out when you’re first starting to use R.<br />

- 226 -

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!