Excel file Import to R
5
0
Entering edit mode
8.2 years ago
Edalat ▴ 30

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 • 4.3k views
ADD COMMENT
0
Entering edit mode

Hello ED!

It appears that your post has been cross-posted to another site:  https://support.bioconductor.org/p/88866/

This is typically not recommended as it runs the risk of annoying people in both communities.

ADD REPLY
2
Entering edit mode
8.2 years ago
TriS ★ 4.7k

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

ADD COMMENT
2
Entering edit mode
8.2 years ago

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

ADD COMMENT
1
Entering edit mode

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

ADD REPLY
1
Entering edit mode
8.2 years ago
ddiez ★ 2.0k

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.

ADD COMMENT
0
Entering edit mode
8.2 years ago
Brice Sarver ★ 3.8k

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)
ADD COMMENT
0
Entering edit mode
8.2 years ago
Sparrow_kop ▴ 260
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 .

ADD COMMENT

Login before adding your answer.

Traffic: 1825 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6