[R] Import Data from Excel
arun
smartpink111 at yahoo.com
Wed Aug 15 23:43:54 CEST 2012
HI,
I guess you were talking about column names instead of rownames.
If you have a data like the one below to read:
dat1<-read.table(text="
beta0 beta1 pvalor Crom
rs17 158.5980 12.252462 9.083193e-135 1
rs46 163.3730 3.304276 3.279925e-06 1
rs63 162.7924 2.084678 5.023893e-06 1
rs24 162.4252 1.837208 5.509042e-06 1
",sep="",header=TRUE,row.names=NULL)
Here, you have column names for four columns, so if you don't add row.names=NULL, then the first column will become the row names.
Now, for the second case: column names will be automatically generated with data frames if your data doesn't have one.
dat2<-read.table(text="
158.5980 12.252462 9.083193e-135 1
163.3730 3.304276 3.279925e-06 1
162.7924 2.084678 5.023893e-06 1
162.4252 1.837208 5.509042e-06 1
",sep="",header=FALSE)
colnames(dat2)<-NULL # will create NA's as column names.
colnames(dat2)<-c(1,2,3,4) # will replace V1,V2, etc. with 1,2,..
Bu, converting to matrix, can solve this problem in this case,
dat3<-as.matrix(dat2)
colnames(dat3)<-NULL
dat3
# [,1] [,2] [,3] [,4]
#[1,] 158.5980 12.252462 9.083193e-135 1
#[2,] 163.3730 3.304276 3.279925e-06 1
#[3,] 162.7924 2.084678 5.023893e-06 1
#[4,] 162.4252 1.837208 5.509042e-06 1
Is there any specific reason to eliminate the column names??
A.K.
----- Original Message -----
From: li li <hannah.hlx at gmail.com>
To: r-help <r-help at r-project.org>
Cc:
Sent: Wednesday, August 15, 2012 5:04 PM
Subject: [R] Import Data from Excel
Dear all,
I want to import just part of an excel data file into R.
I would like to have the data imported without
rownames or colume names.
I used read.delim("clipboard", header=F). Somehow even though
I added the argument "header=F", I still have the row names V1, V2, ...,
Does anyone know how to fix this?
Thanks very much in advance.
Hannah
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list