R read data from csv files

Reading data from csv files is very useful as csv file is a standard output of many programs. In R, you can read csv file in one line: df <- read.csv("/path/to/file.txt", row.names=1,head=FALSE, sep=",")df <- read.csv("/path/to/file.txt", row.names=1,head=FALSE, sep=",") The code above specifies the first column is just a name by using row.names=1. By using head=FALSE, it … Read more

R Write a Date Frame to CSV File

In R, we can easily write a date frame object to a csv file. By using the method write.csv, the csv file can be generated under the same directory of your R script. write.csv(dataFrame, file=”median.csv”)

Install R on Mac

Installing R on Mac is very easy. Just download the installation file here: http://cran.r-project.org/bin/macosx/. The bin files will be automatically added to the PATH.

Install R on Windows

Installing R on Windows is pretty straightforward. Just go to the page and download the installation file here. Remember you need to add the bin directory to your “Path” environment variable.

Get Argument Value from Command Line in R

Sometimes, you may want to run R Script by using command line. In this way, you can write a bash script and schedule a task everyday. In addition you can also pass different arguments to the R program. Create a R script “GetARgument.R”: args

Read File in R Line by Line

The R code below reads a file line by line. path <- "/path/to/the/file" print(path)   conn <- file(path,open="r") lines <- readLines(conn) for (i in 1:length(lines)){ print(lines[i]) } close(conn)path <- "/path/to/the/file" print(path) conn <- file(path,open="r") lines <- readLines(conn) for (i in 1:length(lines)){ print(lines[i]) } close(conn)