R: read.delim2 .txt file and calulate mean of 5 classes

################################################################################
# MC TEST data set by H.Wright                                                 |
#                                                                              |
#                                                                              | 
################################################################################
# set working directory file path
setwd("D:\Projects\R_analysis\mc_30.12.2010\")
# load the test marechiara dataset 
read.delim2 (file="D:\Projects\R_analysis\mc_30.12.2010\mc_test1.txt", 
          na.strings = "NA", 
          nrows = -1,
          skip = 0, 
          check.names = TRUE, 
          strip.white = FALSE, 
          blank.lines.skip = TRUE)
# assign data table to object 'mc' 
mc<-(read.delim2  (file="D:\Projects\R_analysis\mc_30.12.2010\mc_test1.txt", 
          na.strings = "NA", 
          nrows = -1, 
          skip = 0, 
          check.names = TRUE, 
          strip.white = FALSE, 
          blank.lines.skip = TRUE))
# obtain the data table column variables
names(mc)
#[1] "year"    "Acartia.clausi"     "Acartia.danae"      "Acartia.discaudata" "Acartia.longiremis" "Acartia.margalefi"      
 
#define variables in object mc
  col2 <-mc$Acartia.clausi
  col3 <-mc$Acartia.danae
  col4 <-mc$Acartia.discaudata
  col5 <-mc$Acartia.longiremis
  col6 <-mc$Acartia.margalefi
#take the mean of each variable
     mean(col2)
          mean(col3)
               mean(col4)
                    mean(col5)
                         mean(col6)

Created by Pretty R at inside-R.org

Advertisements

Tags: , , , , ,

About hawright

marine ecologist

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: