Install R

[This article was first published on DataSurg » Tag » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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")

 

To leave a comment for the author, please follow the link and comment on their blog: DataSurg » Tag » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)