From Excel (.xls, .txt, .csv)

You can read in an external data set from a .txt or .csv file using the functions read.table() or read.csv(). If your data is in Excel, the easiest option is first convert your .xls into a .csv (using Save As…). Once your spreadsheet has been converted to a .csv, you can import it and store it in a R dataframe as follows:

catch_effort <- read.csv(file="sample_data.csv") # your table is now stored in the object 'catch_effort'
head(catch_effort) # have a look at the first 6 rows
##   Yr.Month   Yr Month Vessels Trips Sea.Days Hooks.100    ALB.mt    BET.mt
## 1  2010-01 2010     1       9   101       13      1790 241.63958  4.922446
## 2  2010-02 2010     2      16    89       21      1685  70.58278  1.537357
## 3  2010-03 2010     3       9    93       22      1688  67.66562  6.242182
## 4  2010-04 2010     4      11   102       17      2836 109.43606 10.358611
## 5  2010-05 2010     5      17   167       33      3446 333.18782 17.738877
## 6  2010-06 2010     6      11   161       28      3327 262.93567 16.185670
##      YFT.mt   OTH.mt ALB.no BET.no YFT.no OTH.no
## 1  7.497130 43.80626  18680    253    959    227
## 2  5.039798 21.12126   3639     90    296    133
## 3  4.291998 18.62458   4791    326    187    100
## 4  4.558048 18.19926   5609    301    172     80
## 5 17.786435 30.26229  22843    853    900    176
## 6 16.482259 31.17723  10351    839    856    193

Ps: you can read in a .xls file directly but you will need to install the gdata library first, and you might have to install an additional software (Perl).

From R (.RData)

If your data has already been formatted and saved as a R object, you can import it directly using load(). Files with the extension .RData contain R objects, load them with the argument verbose=TRUE so that the name of the objects gets printed out.

load('catch.RData', verbose=TRUE)
## Loading objects:
##   catch_effort

Copyright © 2017 Pacific Community. All rights reserved.