Chapter 2 R code - Commands for lecture describing dataframes Comments are preceded with number signs Data in R are stored in objects called dataframes

Chapter 2 R code - Commands for lecture describing...

This preview shows page 1 - 2 out of 3 pages.

# Commands for lecture describing dataframes # Comments are preceded with number signs # Data in R are stored in objects called dataframes # a data frame is like a matrix with n rows and m columns, but can also store non-numeric variables # Simple variables types are: numeric, text, logical # Examples: # use gets operator to assign a value to the variable x #numeric x<-3+2 # text x<-"blue" # logical y<- x=="blue" # to read data into a dataframe, it is easiest to have a text file containing your data # if your data are stored in excel (or similar), then you can save as text before reding into R # in this example we will work with a tab-delimited text file "worms" containing the data (show file) # the first row of the file is a header row giving the variable names for each column # we read in the text file and create a dataframe using the read.table() function in R # look at the help file ?read.table # access the documentatio using ?"function name" # YOU SHOULD EDIT THE PATH NAME TO CORRESPOND TO WHERE YOU HAVE LOCATED THE FILE worms<-read.table("C:\\Documents and Settings\\Farouk N\\Desktop\\teaching\\data_analysis\\R_examples\\worms.txt", header=T,row.names=1)
Image of page 1
Image of page 2

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture