R Basics

October 7, 2009
by Jeremy Koelmel (jpk07)

R basics
October 7, 2009
by Jeremy Koelmel (jpk07)

R Basics, Here is how to:
1) to manually set up data in R
2) Import data from outside R (as .txt)
3) export data out of R (as .txt)
4) To export and import R code to run in R

# writing simple exponential data in R
#assign arrays
X <- c(1:10);
Y <- c(X^2);
XYdata <- cbind(X,Y);
#transpose data
XYdata <- t(XYdata);
#select one
# Plot
plot(X, Y, main=”Exponential Function”);

write.table(XYdata, file=”Desktop/XYdata.txt”, sep=”,”);
#getting the working directory
#setting the working directory

RoseData <- read.table(file=”RoseData.txt”);
#see all plots
plot(RoseData, main=”Multiflora Rose Distribution in a Pine Stand”);
#comparing two variables
MFRdensity <- RoseData[,3];
DistanceFromEdge <- RoseData[,9];
#lm(DistanceFromEdge,MFRdensity); not working because more than one instance of y for single x
# Writing .R function: Write in a simple text format (.txt) and Save as “blahblah”.R

# ie. in this format
X <- c(1:10);
Y <- c(X^2);
XYdata <- cbind(X,Y);
plot(X, Y, main=”Exponential Function”);

# get to the right directory
# enact it in R

Love Jeremy

PS: Further Resources:



Leave a Reply

You must be logged in to post a comment.