There are several ways to import data into R.
The standard way, what it used to be, is from a text file using read.table() function.
For excel files, the most famous spreadsheet software on the world, several libraries can be used to import data from .xls file, for example
. In the past, the problem was with the xlsx file, which was not supported yet.
Recently, I discovered that
can be used to import xlsx file now. So, this bypass the step that I normally have to save the excel file to text file and do the regular file import.
data <- read.xls(xls="myData.xlsx",sheet=1,header=TRUE, as.is=TRUE)
If Rstudio complains about failure to set default locale,
$ defaults write org.R-project.R force.LANG=en_US.UTF-8
I’ve come across a problem needing to transpose to wide table into a long format. I’m not talking about the longitudinal data quite yet, the one where you have one individual getting multiple measurements over time.
The question then is get a lot simpler than having to manipulate longitudinal data, which you can do with
in R. See:
has come into my rescue. With fread function reading in large data frame (or data table) has become much faster. Therefore, base on the simple fread and write.table. here comes the transpose function. You can get the script from my short script
transposeR.r github Genetics Library (which has just recently been updated).
Rscript transposeR.r data_1.txt data_2.txt
You can also use wildcard.
Rscript transposeR.r data_?.txt
I mostly tested it on mac, if your windows machine doesn’t play with
ls command then, the script might not work with multiple file wildcard.
In the past, whenever we want to install a package on Bioconductor. The first thing that we have to do is to “source” the
The good news is that there is a new package “BiocInstaller”, which can help you install Bioconductor package.
Here’s an example to install a library that will help to work with NHGRI’s GWAS catalog
You can use
to source your script from online resource.
However, source doesn’t work if you have https link,
Here’s some solutions I found on stack overflow.
eval(expr = parse( text = getURL"http://www.mayin.org/ajayshah/KB/R/tutorial.R", ssl.verifypeer=FALSE))
via Sourcing R script over HTTPS – Stack Overflow.
Feel like I’ve done this a million time since I came back to work in Thailand. This should work for R user not using R-studio as well. Configuring R to Use an HTTP Proxy / FAQ / Knowledge Base – RStudio Support. In brief, you can use the command template below in each of the R session.
I found that this is more convenient for me who carry my laptop around. And the only place that won’t let me work at ease is when I am at the office. So, the work around will need to be used occasionally.
If you would like to check your current proxy setting, you can do
*Note*: Please note the capital “S” at the beginning of the command follows by all small letters afterwards.
This sounds like a problem that statisticians occasionally have to deal with. It is quite simple, just convert the string to date or time if you remember what command to use. If your date variable has a value like this 2007-05-31 for May 31, 2007. You can simply use the example below.
For more example on date, I refer you to UCLA R-help page:
R FAQ: How can I format a string containing a date into R “Date” object??.
For a complete list of date-time formatting conversion see this