Install R

Video

Files

This file contains data on pain score after laparoscopic vs. open hernia repair. Age, gender and primary/recurrent hernia also included. The ultimate aim here is to work out which of these factors are associated with more pain after this operation.

lap_hernia

Script

##########################
# Getting started with R #
# Ewen Harrison          #
# April 2013             #
# www.datasurg.net       #
##########################

# Anything after a "#" is a comment and is not run
# Run a line or selection of lines with Ctrl-R

# Create a working directory
# Copy the address of the working directory
# Click on the R console window
# File > Change dir ...
# Paste address into Folder and hit OK. 
# Can also use command
# setwd("C:/Users/Administrator/R")
# but note \ need changed to /, which is a pain so above method easier.

# Import data from a csv file.
# You can export from Excel in .csv format. 
# This is often easier than importing an .xls file

# Read.table into an "object". It can be called anything.
# I've used "data" here, but can be anything
# Ensure file is in working directory.

data<-read.table("lap_hernia.csv", sep=",", header=TRUE)

# Check no errors in console.
# List objects in workspace
ls()

# Summarise data
summary(data)
str(data)
head(data)
tail(data)
data[1:5,] # first 5 lines
data[,1:5] # first 5 columns

# Get help
# If you know the exact command
?read.table
# or
help(read.table)

# If you don't know the exact command.
??read

# Help with a package.
help(package="ggplot2")

 

Leave a Reply

Your email address will not be published. Required fields are marked *