3.2 Importing the Spreadsheet into Rstudio

To get our data into R, we need to save our data in a format and at a place where RStudio can open it.

3.2.1 Saving the data in the right format

Generelly, finding the right format to import Excel can be tricky.

  • If you’re using a PC or Mac, it is advised to save your Excel sheet as a comma-separated-values (.csv) file. This can be done by clicking on “save as” and then choosing (.csv) as the output format in Excel.
  • With some PCs, RStudios might not be able to open such files, or the files might be distorted. In this case, you can also try to save the sheet as a normal .xslx Excel-file and try if this works.

3.2.2 Saving the data in your working directory

To function properly, you have to set a working directory for RStudio first. The working directory is a folder on your computer from which RStudio can use data, and in which output it saved.

  1. Therefore, create a folder on your computer and give it a meaningful name (e.g. “My Meta-Analysis”).
  2. Save your spreadsheet in the folder
  3. Set the folder as your working directory. This can be done in RStudio on the bottom-right corner of your screen. Under the tile “Files”, search for the folder on your computer, and open it.
  4. Once you’ve opened your folder, the file you just saved there should be in there.
  5. Now that you’ve opened the folder, click on the little gear wheel on top of the pane

  1. Then click on “Set as working directory

Your file, and the working directory, are now where they should be!

3.2.3 Loading the data

  1. To import the data, simply click on the file in the bottom-right pane. Then click on Import Dataset…
  2. An import assistant should now pop up, which is also loading a preview of your data. This can be time-consuming sometimes, so you can skip this step if you want to, and klick straight on “Import”

As you can see, the on the top-right pane called Environment, your file is now listed as a dataset. This means that your data is now loaded and can be used by R and R code commands. Tabular datasets like the one we imported here are called data frames (data.frame) in R lingo; so when someone is referring to a data frame, know that what she or he is talking about is dataset with columns and rows just like the Excel spreadsheet we imported.

  1. I also want to give my data a shorter name: madata. To rename it, I use the following code:
madata <- Meta_Analysis_Data

This “copies” the data, and gives the copy the name madata. The madata dataset now also appears in the Environment pane, which means that it is also loaded into R and usable via code commands.

  1. Now, let’s have a look at the structure of my data using the str() function.
## tibble [18 × 15] (S3: tbl_df/tbl/data.frame)
##  $ Author               : chr [1:18] "Call et al." "Cavanagh et al." "DanitzOrsillo" "de Vibe et al." ...
##  $ TE                   : num [1:18] 0.709 0.355 1.791 0.182 0.422 ...
##  $ seTE                 : num [1:18] 0.261 0.196 0.346 0.118 0.145 ...
##  $ RoB                  : chr [1:18] "low" "low" "high" "low" ...
##  $ Control              : chr [1:18] "WLC" "WLC" "WLC" "no intervention" ...
##  $ intervention duration: chr [1:18] "short" "short" "short" "short" ...
##  $ intervention type    : chr [1:18] "mindfulness" "mindfulness" "ACT" "mindfulness" ...
##  $ population           : chr [1:18] "undergraduate students" "students" "undergraduate students" "undergraduate students" ...
##  $ type of students     : chr [1:18] "psychology" "general" "general" "general" ...
##  $ prevention type      : chr [1:18] "selective" "universal" "universal" "universal" ...
##  $ gender               : chr [1:18] "female" "mixed" "mixed" "mixed" ...
##  $ mode of delivery     : chr [1:18] "group" "online" "group" "group" ...
##  $ compensation         : chr [1:18] "none" "none" "voucher/money" "voucher/money" ...
##  $ instruments          : chr [1:18] "DASS" "PSS" "DASS" "other" ...
##  $ guidance             : chr [1:18] "f2f" "self-guided" "f2f" "f2f" ...

Although this output looks kind of messy, it’s already very informative. It shows the structure of my data. In this case, i used data for which the effect sizes were already calculated. This is why the variables TE and seTE appear. I also see plenty of other variables, which correspond to the subgroups which were coded for this dataset.

Here is a (shortened) table created for my data

Author TE seTE RoB Control intervention duration intervention type
Call et al. 0.7091362 0.2608202 low WLC short mindfulness
Cavanagh et al. 0.3548641 0.1963624 low WLC short mindfulness
DanitzOrsillo 1.7911700 0.3455692 high WLC short ACT
de Vibe et al. 0.1824552 0.1177874 low no intervention short mindfulness
Frazier et al. 0.4218509 0.1448128 low information only short PCI
Frogeli et al. 0.6300000 0.1960000 low no intervention short ACT
Gallego et al. 0.7248838 0.2246641 high no intervention long mindfulness
Hazlett-Stevens & Oren 0.5286638 0.2104609 low no intervention long mindfulness
Hintz et al. 0.2840000 0.1680000 low information only short PCI
Kang et al. 1.2750682 0.3371997 low no intervention long mindfulness
Kuhlmann et al. 0.1036082 0.1947275 low no intervention short mindfulness
Lever Taylor et al. 0.3883906 0.2307689 low WLC long mindfulness
Phang et al. 0.5407398 0.2443133 low no intervention short mindfulness
Rasanen et al. 0.4261593 0.2579379 low WLC short ACT
Ratanasiripong 0.5153969 0.3512737 high no intervention short mindfulness
Shapiro et al. 1.4797260 0.3152817 low WLC long mindfulness
SongLindquist 0.6125782 0.2266834 high WLC long mindfulness
Warnecke et al. 0.6000000 0.2490000 low information only long mindfulness