[R] sample

Adaikalavan Ramasamy ramasamy at cancer.org.uk
Sat Feb 12 02:36:50 CET 2005


See comments below.


On Fri, 2005-02-11 at 08:47 -0800, T. Murlidharan Nair wrote:
> Thanks to all for trying to help me with problem. After spending a long 
> time, I eventually solved it
> by writing a perl script and transposing the matrix 

If you plan on doing your analysis mostly in R, it would be best to use
R directly. While perl is great for many things, I recommend caution
with numerical data (e.g. it will happily add a character and a number)

Besides, you may risk extra computing overhead and debugging nightmares.


> and re-reading the file. When I did this I got an
> error saying I had duplicate row names (which in fact was not true or 

How did you read the file ? e.g. read.delim, read.table, read.csv, ...

> may be something to with
> the naming conventions in R).
> The column names were  :

Wouldn't this become row names after you transpose it ? Nevermind, I
have tested both cases below.


> Tumor_VA_114-1, Tumor_VA_114-2,.....
> But when I changed it to Tumor_VA_114_1, Tumor_VA_114_2 it worked fine.
> I was not aware that - cannot be used to differentiate variables. Is 
> this the case ?

Not true. I successfully read in (tab delimited) files containing either
of the following contents in Redhat Fedora Core 3 and R-1.9.1 :

read.delim(file="file1.txt", row.names=1, header=TRUE)
read.delim(file="file2.txt", row.names=1, header=TRUE)

----------------- File 1 ---------------------
Index	Tumor_VA_114-1	Tumor_VA_114-2
A	10	100
B	20	200
----------------------------------------------

----------------- File 2 ---------------------
Index	Value
Tumor_VA_114-1	100
Tumor_VA_114-2	200
---------------------------------------------

Another possibility is that somehow you are using "-" as the field
separator. 

Maybe some other software that use in between corrupted the dimnames ?

We can only guess since you have not provided neither a simple
reproducible example, your operating system or working R version. Please
read the posting guide first.


> Sorry, if I wasted any of your time.
> Cheers ../Murli
> 
> 
> 
> Liaw, Andy wrote:
> 
> >?sample says:
> >
> >x   Either a (numeric, complex, character or logical) vector of more
> >    than one element from which to choose, or a positive integer 
> >
> >so I guess it wasn't meant to be used on a data frame.  However, a data
> >frame is a list (where the variables are the components), and a list is a
> >vector, so the behavior is consistent:
> >
> >  
> >
> >>x <- list("a", 2, "c", 4, "e", "f")
> >>sample(x)
> >>    
> >>
> >[[1]]
> >[1] "c"
> >
> >[[2]]
> >[1] "a"
> >
> >[[3]]
> >[1] 4
> >
> >[[4]]
> >[1] 2
> >
> >[[5]]
> >[1] "f"
> >
> >[[6]]
> >[1] "e"
> >
> >Andy
> >
> >  
> >
> >>From: Jean Eid
> >>
> >>It seems that sample picks columns when the object is turned into a
> >>data.frame. I do not knoe why it is doing that....
> >>
> >>Is this something that was meant and not documented or something?
> >>
> >>
> >>Jean
> >>
> >>
> >>On Fri, 11 Feb 2005, Adaikalavan Ramasamy wrote:
> >>
> >>    
> >>
> >>>See below.
> >>>
> >>>On Thu, 2005-02-10 at 14:53 -0800, T. Murlidharan Nair wrote:
> >>>      
> >>>
> >>>>Just to explain my previous mail, here is the output I get.
> >>>>
> >>>>
> >>>> > dim(tissue.exp)
> >>>>[1] 1532   20
> >>>>        
> >>>>
> >>>What is this object ? Try class(tissue.exp)
> >>>
> >>>      
> >>>
> >>>> > pick<-sample(tissue.exp,5,replace=TRUE)
> >>>> > dim(pick)
> >>>>[1] 1532    5
> >>>>        
> >>>>
> >>>>From help(sample) :
> >>>
> >>>    sample(x, size, replace = FALSE, prob = NULL)
> >>>
> >>>    x: Either a (numeric, complex, character or logical) vector of
> >>>       more than one element from which to choose, or a positive
> >>>       integer.
> >>>
> >>>x has to be a vector or positive integer integer. I am not 
> >>>      
> >>>
> >>sure how you
> >>    
> >>
> >>>got "sample" to work on tissue.exp in the first place. Maybe you got
> >>>your own version of "sample".
> >>>
> >>>
> >>>      
> >>>
> >>>> > tissue.exp.t<-t(tissue.exp)
> >>>> > dim(tissue.exp.t)
> >>>>[1]   20 1532
> >>>> > pick<-sample(tissue.exp.t,5,replace=TRUE)
> >>>> > dim(pick)
> >>>>NULL
> >>>>
> >>>>--------
> >>>>Thanks ../Murli
> >>>>
> >>>>______________________________________________
> >>>>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
> >>    
> >>
> >>>      
> >>>
> >>______________________________________________
> >>    
> >>
> >>>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
> >>    
> >>
> >>______________________________________________
> >>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
> >>
> >>
> >>    
> >>
> >
> >
> >------------------------------------------------------------------------------
> >Notice:  This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as Banyu) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message.  If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system.
> >------------------------------------------------------------------------------
> >  
> >
> 
> ---
> 
> 
> 
>




More information about the R-help mailing list