This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Excel file Import to R

Hi All, I am trying to import data to R, my data has 28031 rows, I want to change rownames to list of genes, what should I do?

     [,1]  [,2]  [,3]

Fkh2 0.141 0.242 0.342

Swi5 0.224 0.342 0.334

Sic1 0.652 0.682 0.182

I found this function, but it is not possible to use for 28031 genes!!

Convert to matrix as it is that you wanted:

test2<-as.matrix(test1)

colnames(test2)<-NULL

genelist<-c("Fkh2","Swi5","Sic1")

 rownames(test2)<-genelist

test2
r

5 answers

where is your list of genes right now?

library(gdata)
xls_file <- read.xls("myFIle.xls",sheet=1)
rownames(xls_file) <- myVectorWithGeneNames

you don't need to convert to matrix more info here on r-bloggers

I have found very useful for my novice students to use the integrated functions included in RStudio to import data that ddiez mention

This provides not only a GUI interface to import data, but also a Data preview. It will allow you to convert the data name column into row names automatically. You will be alerted if your numeric data will be converted to character or not

The newest preview version 1.0.44 can import, in addition to the classical csv and excel files, SPSS, SAS and Stata files. This is accessed from the File / Import Dataset menu file

The nice thing is that it also provide the R code to do it, so you can learn from the experience

Good point about the R code used to import the data- its a great way to learn.

Another option to read XLS files into R is the readxl package. If you are using the preview version of RStudio this is integrated in the GUI.

I'm assuming you know what gene corresponds to each row. If they're in order, do something like:

a <- read.table("your_table_with_values.txt", stringsAsFactors=FALSE)
b <- [this is going to depend on what format your gene names are in. 
perhaps you could read as a table and take a single column, or use scan() to read
a single line]
#all you need to do is cbind() them:
d <- cbind(b, a)
library(xlsx)
DT <- read.xlsx(file='you excel file')

you can use this package to read excel file and convert to data frame in R .

Log in to answer this question.