``The R Page" (November 5, 2014)


  1. R instructions

  2. Example input data file.

  3. I have posted a sample session *.txt log generated by the two files above.

  4. The session creates the files data3.txt and data3.csv and summary.tex .

  5. To process the summary.tex file, add in latex boilerplate to get summary1.tex and then run it through latex to get summary1.pdf.
  6. By using save-as commands during the session, one can save the plots that are created, in the format of your choice. Examples are r-fig1- histogram.bmp and r-fig2-scatter.pfd.pdf and r- fig3-kernel.density.tif and r-fig-regression.jpg.


To list the files in the current directory: list.files().
To list the variables in the current dataset: names(mydata) or str(mydata) Do NOT use ls().

Reading in data:
rm(list=ls(all=TRUE))#cleans up and removes everything from memory
rdata <- read.csv("nov1data.csv")
nov1data <-as.data.frame(lapply(rdata,as.numeric))
attach(nov1data)
#creates a new dataset that is rdata made numeric, and uses it
remove(rdata)
save(list = ls(all = TRUE), file= "nov1data.RData")
remove(nov1data)
load("nov1data.RData")
ls() # to check that nov1data is reloaded, and nothing else.

WRITING OUT DATA:
library(xlsx)
write.xlsx(mydata, "c:/mydata.xlsx") #I didn't check this.
write.table(mydata, "mydata.csv", sep=",")#Didn't check yet.
# export data frame to Stata binary format
library(foreign)
write.dta(nov1data, "junk.dta") #this worked.



Location: http://www.rasmusen.org/a/r.htm

Comments: Erasmuse@Indiana.edu.