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.

An alternative method is to use the who() function, as long as you tell it to look at the variables inside<br />

data frames. If you set exp<strong>and</strong> = TRUE then it will not only list the variables in the workspace, but it will<br />

“exp<strong>and</strong>” any data frames that you’ve got in the workspace, so that you can see what they look like.<br />

That is:<br />

> who(exp<strong>and</strong> = TRUE)<br />

-- Name -- -- Class -- -- Size --<br />

expt data.frame 9 x 4<br />

$age numeric 9<br />

$gender factor 9<br />

$group factor 9<br />

$score numeric 9<br />

or, since exp<strong>and</strong> is the first argument in the who() function you can just type who(TRUE). I’ll do that a lot<br />

in this book.<br />

4.8.4 Looking <strong>for</strong> more on data frames?<br />

There’s a lot more that can be said about data frames: they’re fairly complicated beasts, <strong>and</strong> the<br />

longer you use R the more important it is to make sure you really underst<strong>and</strong> them. We’ll talk a lot more<br />

about them in Chapter 7.<br />

4.9<br />

Lists<br />

ThenextkindofdataIwanttomentionarelists. Lists are an extremely fundamental data structure<br />

in R, <strong>and</strong> as you start making the transition from a novice to a savvy R user you will use lists all the<br />

time. I don’t use lists very often in this book – not directly – but most of the advanced data structures<br />

in R are built from lists (e.g., data frames are actually a specific type of list). Because lists are so<br />

important to how R stores things, it’s useful to have a basic underst<strong>and</strong>ing of them. Okay, so what is a<br />

list, exactly? Like data frames, lists are just “collections of variables.” However, unlike data frames –<br />

which are basically supposed to look like a nice “rectangular” table of data – there are no constraints on<br />

what kinds of variables we include, <strong>and</strong> no requirement that the variables have any particular relationship<br />

to one an<strong>other</strong>. In order to underst<strong>and</strong> what this actually means, the best thing to do is create a list,<br />

which we can do using the list() function. If I type this as my comm<strong>and</strong>:<br />

> Dan print( Dan )<br />

$age<br />

[1] 34<br />

- 102 -

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

Saved successfully!

Ooh no, something went wrong!