[R] read.table without sep
P Ehlers
ehlers at math.ucalgary.ca
Fri Nov 25 20:29:29 CET 2005
Vasu,
You have a lot of problems here.
1. How was your file generated? Excel? You have trailing tabs on
all but row 1 which is why your read.table call with sep="\t"
gives you columns that don't seem to agree with what you expect.
See the argument row.names in ?read.table.
2. It's never a good idea to use colnames that begin with a digit.
3. read.table creates a _data frame_ for which data[i] would be
a data frame; your function does not accept data frames as input.
You probably want data[,i].
4. One-line 158-character function definitions with no spaces
are not exactly easy to read.
5. It's not clear whether you want the first column to be rownames
or data. R can handle both, but you need to tell it what to do.
6. ***** Best not to send such questions to R-devel. They have
nothing to do with the development of R.
Peter
Vasundhara Akkineni wrote:
> Hello all,
>
> I have a data file table.txt which i have attached. I am trying to pass the
> columns as arguments to a function "totnorm" where i am displaying a total
> normalization plot. The function is given below:
>
> totnorm<-function(x,y){scale<-sum(x)/sum(y);xlab<-colnames(x);ylab<-colnames(y);x1<-x[[1]];y1<-scale*y[[1]];plot(x1,y1,xlab=xlab,ylab=ylab,col=6,
> col.lab=4);}
>
> i tried doing this:
>
> data<-read.table("alldata.txt",header=TRUE,sep="\t")
> a<-data[1]
> b<-data[2]
> totnorm(a,b)
>
> The problem i am facing is- xlab and ylab contain the column names of
> data[1] and data[2], but data[1][[1]] which is assigned to x1 has different
> data which does not correspond to the colname(data[1]). Stating more
> clearly, the colnames and the coldata don't match. I tried usind
> read.tablewithout sep attribute, as given below:
>
> data1<-read.table("alldata.txt",header=TRUE)
>
> But this statement is not getting executed using Rserve when i make a
> connection to R and try to execute it from a java servlet. I don't know why
> it was doing so, so thought it would be better to fix this on R side, i.e,
> try to use the "sep" attribue in read.table and still make the colnames and
> coldata point to the same col#.
>
> Please suggest a solution.
> Thanks,
> Vasu.
>
>
> ------------------------------------------------------------------------
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
--
Peter Ehlers
Department of Mathematics and Statistics
University of Calgary, 2500 University Dr. NW ph: 403-220-3936
Calgary, Alberta T2N 1N4, CANADA fax: 403-282-5150
More information about the R-help
mailing list