Stacks Image 20108

For Academics

Data import export

Notes on basic import and export in R.

Import

mydata <- read.table("/Users/useraccount/Desktop/R/inputFile.txt", header=T)

Importing comma separated value files can be useful, because they retain gaps in column names. This is useful if the column names are used in graphs.

mydata <- read.csv("/Users/useraccount/Desktop/R/inputFile.csv", header=T)

I tend to copy data files to the desktop from wherever I store them. It makes the code work regardless of where the data end up.

Inspection

Quickly check the first rows of the data, useful if the data file is large

head(mydata)

Print the first values of the data to check data are factors or numerals, and generally that the import is as expected.

str(mydata)

Numeric variables may be read as factors, for example if they include NA values.

To convert a numeric variable that was imported erroneously as a factor

mydata$copLatency <- as.numeric(as.character(mydata$copLatency))

Export

To export a data.frame 'frameName' as a txt file:

write.table(dataFrameName, file="out.txt", quote=F, row.names=F, sep="\t")
Previous Post 3 / 10 Post

Tag:

Sex chromosome papers RSS


The genome sequence of the Four-spotted Footman moth, Lithosia quadra (Linnaeus, 1758)
Link

Chromosome-level genomes of Arctic and Antarctic mosses: Aulacomnium turgidum and Polytrichastrum alpinum
Link

Multiple Sry genes with an A-to-S substitution in the HMG domain retain DNA-binding ability in the Okinawa spiny rat
Link