Re: [R] counting the duplicates in an object of list

2011-09-07 Thread zhenjiang xu
, and the fourth once. How to organize that the best depends on what you want to do with the data. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of zhenjiang xu Sent: Wednesday

Re: [R] how to create data.frames from vectors with duplicates

2011-09-07 Thread zhenjiang xu
, Aug 31, 2011 at 9:50 AM, Jorge I Velez jorgeivanve...@gmail.com wrote: Hi Zhenjiang, Try table(unlist(mapply(function(x, y) rep(x, y), y, x))) Yikes! How about simply tapply(x,y,sum) ?? ?tapply -- Bert HTH, Jorge On Wed, Aug 31, 2011 at 12:45 PM, zhenjiang xu wrote

Re: [R] read.table truncated data?

2011-09-07 Thread zhenjiang xu
: x - read.table(, comment.char = '', quote = '') Most cases is that there is a missing quote somewhere in your data. use a text editor and search for single and double quotes. On Thu, Aug 25, 2011 at 11:49 AM, zhenjiang xu zhenjiang...@gmail.com wrote: Thanks for your

Re: [R] counting the duplicates in an object of list

2011-09-07 Thread zhenjiang xu
YOLWTy1-1 YOL103W-B [49] YORWTy1-2 YOR142W-B YPLWTy1-1 YPL257W-B YPRCTy1-2 YPR137C-B [55] YPRWTy1-3 YPR158W-B YPRCTy1-4 YPR158C-D On Wed, Sep 7, 2011 at 9:15 PM, zhenjiang xu zhenjiang...@gmail.com wrote: Thanks, Bill. match() is nice and efficient. However, I met a problem: My real data

Re: [R] how to create data.frames from vectors with duplicates

2011-09-07 Thread zhenjiang xu
HTH, Dennis On Wed, Sep 7, 2011 at 6:18 PM, zhenjiang xu zhenjiang...@gmail.com wrote: Thanks for all your replies. I am using rowsum() and it looks efficient. I hope I could do some benchmark sometime in near future and let people know. Or is there any benchmark result available

Re: [R] counting the duplicates in an object of list

2011-09-07 Thread zhenjiang xu
., ac - sapply(a, function(ai) paste(collapse=\n, deparse(ai))) and use match on that. You can use the indices it returns on the original list. ** ** Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com *From:* zhenjiang xu [mailto:zhenjiang...@gmail.com] *Sent

Re: [R] counting the duplicates in an object of list

2011-09-07 Thread zhenjiang xu
solution would be to avoid the internal use of deparse when using match() or unique() on lists and to hash the list element directly, but that is a fair bit of work. ** ** Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com *From:* zhenjiang xu [mailto:zhenjiang

[R] counting the duplicates in an object of list

2011-08-31 Thread zhenjiang xu
Hi all, I have a list x:   x=list(a=c('1','2'),b=c('2','3'),c=c('1','2'),d=c('2','3')) I can get the unique elements with unique(), but how can I get the number of duplicates for each unique elements? unique(x) [[1]] [1] 1 2 [[2]] [1] 2 3 Thanks -- Best, Zhenjiang

Re: [R] sum of two lists

2011-08-31 Thread zhenjiang xu
Thanks, Henrique. It works. On Mon, Aug 29, 2011 at 6:45 PM, Henrique Dallazuanna www...@gmail.com wrote: Try this: as.list(colSums(merge(m, n, all = TRUE), na.rm = TRUE)) On Mon, Aug 29, 2011 at 7:39 PM, zhenjiang xu zhenjiang...@gmail.com wrote: Hi R users, Suppose I have two lists

[R] how to create data.frames from vectors with duplicates

2011-08-31 Thread zhenjiang xu
Hi R users, suppose I have two vectors, x=c(1,2,3,4,5) y=c('a','b','c','a','c') How can I get a data.frame like this? xy count a 5 b 2 c 8 I know a few ways to fulfill the task. However, I have a huge number of this kind calculations, so I'd like an efficient solution.

[R] sum of two lists

2011-08-29 Thread zhenjiang xu
Hi R users, Suppose I have two lists and the names of list 'm' are a subset of those of 'n', how can I sum the two lists with corresponding elements added together to get list 'o'? n = list(a=1,b=3,c=5) m = list('b'=4) o $a [1] 1 $b [1] 7 $c [1] 5 Thanks -- Best, Zhenjiang

Re: [R] read.table truncated data?

2011-08-25 Thread zhenjiang xu
yes ETS1-2 - ETS1-2 chr12:466869-467569 WT air2rrp6OK 3258.97 1114.76 -1.072772.91211 0.00359 0.0121597 yes On Wed, Aug 24, 2011 at 2:34 PM, Sarah Goslee sarah.gos...@gmail.comwrote: Hi, On Wed, Aug 24, 2011 at 2:18 PM, zhenjiang xu zhenjiang

Re: [R] read.table truncated data?

2011-08-25 Thread zhenjiang xu
editor and search for single and double quotes. On Thu, Aug 25, 2011 at 11:49 AM, zhenjiang xu zhenjiang...@gmail.com wrote: Thanks for your replies. I looked at those lines and didn't spot anything unusual. tail(a) test_id gene_id gene locus sample_1 sample_2 status

[R] read.table truncated data?

2011-08-24 Thread zhenjiang xu
Hi R users, I was using read.table to read a file. The data.fame looked alright, but I found not all rows are read by the read.table. What's wrong with it? It didn't give me any warning or error messages. Why the data are truncated? Thanks. $ wc -l all/isoform_exp.diff 42847 all/isoform_exp.diff

Re: [R] a question on list manipulation

2011-08-06 Thread zhenjiang xu
), B=c(d, e), C=c(d)) x2 - unique(unlist(x)) w - lapply(x, function(u) names(x)[which(x2 %in% u)]) names(w) - x2 w $d [1] A B C $e [1] A B $f [1] A HTH, Dennis On Fri, Aug 5, 2011 at 10:04 AM, zhenjiang xu zhenjiang...@gmail.com wrote: Exactly! Sorry I get others misunderstood

Re: [R] a question on list manipulation

2011-08-06 Thread zhenjiang xu
-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of zhenjiang xu Sent: Friday, August 05, 2011 11:04 AM To: Duncan Murdoch Cc: r-help Subject: Re: [R] a question on list manipulation Exactly! Sorry I get others misunderstood. The uppercase/lowercase is only a toy example

Re: [R] how to control to save plots to which dev

2011-08-05 Thread zhenjiang xu
confused which dev is the current one. On Tue, Aug 2, 2011 at 1:28 AM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: On Tue, 2 Aug 2011, David Winsemius wrote: On Aug 1, 2011, at 11:14 PM, zhenjiang xu wrote: Hi, I have a for loop to make 2 types of plots and I'd like to save one type

[R] a question on list manipulation

2011-08-05 Thread zhenjiang xu
Hi R users, I have a list: x $A [1] a b c $B [1] b c $C [1] c I want to convert it to a lowercase-to-uppercase list like this: y $a [1] A $b [1] A B $c [1] A B C In a word, I want to reverse the list names and the elements under each list name. Is there any quick way to do that? Thanks

Re: [R] how to control to save plots to which dev

2011-08-05 Thread zhenjiang xu
. Thanks. On Fri, Aug 5, 2011 at 12:02 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 05/08/2011 11:49 AM, zhenjiang xu wrote: Thanks, Prof Ripley. I was using dev.next(), dev.prev(),, but I am wondering, instead of switching the current dev, is there a way to more directly print plot

Re: [R] a question on list manipulation

2011-08-05 Thread zhenjiang xu
the matching, from all the elements to the names of the list. On Fri, Aug 5, 2011 at 12:53 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 05/08/2011 12:05 PM, zhenjiang xu wrote: Hi R users, I have a list:  x $A [1] a  b  c $B [1] b  c $C [1] c I want to convert

[R] how to control to save plots to which dev

2011-08-01 Thread zhenjiang xu
Hi, I have a for loop to make 2 types of plots and I'd like to save one type of plots to a pdf file and the other to another pdf file. How can I control which plot will be saved to which pdf? Thanks -- Best, Zhenjiang __ R-help@r-project.org mailing

[R] how to add two data.frame with the same column but different row numbers

2011-04-15 Thread zhenjiang xu
Hi all, Suppose I have 2 data.frame , a and b, how can I add them together to get c? Thanks a A a 1 b 2 c 3 b A a 6 c 1 c A a 7 b 2 c 4 -- Best, Zhenjiang [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

Re: [R] how to add two data.frame with the same column but different row numbers

2011-04-15 Thread zhenjiang xu
(dfm[, -1], na.rm = TRUE)) x y 1 a 7 2 b 2 3 c 4 HTH, Dennis On Fri, Apr 15, 2011 at 1:31 PM, zhenjiang xu zhenjiang...@gmail.com wrote: Hi all, Suppose I have 2 data.frame , a and b, how can I add them together to get c? Thanks a A a 1 b 2 c 3 b A a 6 c 1

Re: [R] how to add two data.frame with the same column but different row numbers

2011-04-15 Thread zhenjiang xu
Thanks, Gabor. It's a nice workaround. I'll look more at zoo library. On Fri, Apr 15, 2011 at 7:10 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Fri, Apr 15, 2011 at 6:10 PM, zhenjiang xu zhenjiang...@gmail.com wrote: Thanks, Dennis! I'll go with it. It's surprising

[R] how to reshape the data.frame from long to wide in a specific order

2011-03-14 Thread zhenjiang xu
Hi, For example, the data.frame like: origdata.long - read.table(header=T, con - textConnection(' subject sex condition measurement 1 M control 7.9 1 M first12.3 1 Msecond10.7 2 F control 6.3 2 F first

[R] error bars in lattice barchart

2010-11-10 Thread zhenjiang xu
Hi all, I've read the emails of Dan, Deepayan and Sundar about adding error bars to the lattice plots ( https://stat.ethz.ch/pipermail/r-help/2006-October/114883.html), but I still have the problem when I want to adding error bars to barchart. I tried both the solution of Deepayan and Sundar but

[R] ggplot2 problem in interacting mode

2010-11-10 Thread zhenjiang xu
Hi all, When running R interactively, I have the problem as following: library(ggplot2) Loading required package: reshape Loading required package: plyr Attaching package: 'reshape' The following object(s) are masked from 'package:plyr': round_any Loading required package: grid Loading

[R] matrix problem

2010-08-10 Thread zhenjiang xu
Hi, I have a file like this: 1 2 0.1 2 3 0.2 3 1 0.3 And I want to read it to create a matrix like this: [,1] [,2][,3] [1,]0 0.1 0 [2,]0 00.2 [3,]0.300 How can I do it efficiently? Thanks. -- Best, Zhenjiang [[alternative

[R] how to display the value of each data points on the levelplot

2010-05-05 Thread zhenjiang xu
Hi R users, How can I display the corresponding value inside each little square of level plot plotted by the following code? data(Cars93, package = MASS) cor.Cars93 - cor(Cars93[, !sapply(Cars93, is.factor)], use = pair) levelplot(cor.Cars93, aspect = 1, scales = list(x = list(rot = 90)))

Re: [R] a question on autocorrelation acf

2010-04-30 Thread zhenjiang xu
at 7:08 PM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 29/04/2010 6:22 PM, zhenjiang xu wrote: Hi R users, where can I find the equations used by acf function to calculate autocorrelation? See the reference listed in ?acf. Duncan Murdoch I think I misunderstand acf. Doesn't acf

[R] a question on autocorrelation acf

2010-04-29 Thread zhenjiang xu
Hi R users, where can I find the equations used by acf function to calculate autocorrelation? I think I misunderstand acf. Doesn't acf use following equation to calculate autocorrelation? [image: R(\tau) = \frac{\operatorname{E}[(X_t - \mu)(X_{t+\tau} - \mu)]}{\sigma^2}\, ,] If it does, then the

Re: [R] how to reorder of groups and specify ylim for each row in lattice barchart

2010-04-23 Thread zhenjiang xu
),scales = list(x = list(rot = 45), y=list(relation='free', ylim=mylist))) On Thu, Apr 22, 2010 at 7:54 PM, Peter Ehlers ehl...@ucalgary.ca wrote: On 2010-04-21 21:13, zhenjiang xu wrote: R experts, Is there anyway to reorder inside each group? In the following example, the bar of year 1932

Re: [R] the bar width of barchart plot in lattice package

2010-04-23 Thread zhenjiang xu
probably yes. I plotted each row individually instead. Thanks On Fri, Apr 23, 2010 at 11:14 AM, Deepayan Sarkar deepayan.sar...@gmail.com wrote: On Wed, Apr 21, 2010 at 8:55 PM, David Winsemius dwinsem...@comcast.net wrote: On Apr 21, 2010, at 9:51 PM, zhenjiang xu wrote: I tried

[R] a question related to table output

2010-04-23 Thread zhenjiang xu
Hi, I have a data.frame object: a.df Methods Score 1 Northern 1.3544227 2 Northern 0.8302436 3 RT-PCR 1.0011360 4 RT-PCR 1.1149423 If I write it out with write.table, write.table(a.df, file = 'data.txt', quote = FALSE, sep = '\t', row.names = FALSE) the data.txt is looks like:

Re: [R] how to reorder of groups and specify ylim for each row in lattice barchart

2010-04-23 Thread zhenjiang xu
c(,) code? For example: mylist - list(c(0,30), c(40,80), c(0,50), c(0,50), c(0,50), c(0,50)) -Peter Ehlers On 2010-04-23 9:22, zhenjiang xu wrote: Peter, thanks, but that doesn't work. Did I missed something? library(lattice) mylist- list(c(0,30), c(40,80

Re: [R] the bar width of barchart plot in lattice package

2010-04-21 Thread zhenjiang xu
I tried that. It seems the bar width is already maximized, although there is a lot of space between groups of bars. Thank you anyway. On Tue, Apr 20, 2010 at 10:16 AM, David Winsemius dwinsem...@comcast.netwrote: On Apr 20, 2010, at 9:46 AM, zhenjiang xu wrote: Dear R users, I am trying

[R] how to reorder of groups and specify ylim for each row in lattice barchart

2010-04-21 Thread zhenjiang xu
R experts, Is there anyway to reorder inside each group? In the following example, the bar of year 1932 is always plotted before the bar of year 1931, may I change the order inside each groups of bars? library(lattice) barchart(yield ~ variety | site,data=barley, groups = year, layout =

[R] the bar width of barchart plot in lattice package

2010-04-20 Thread zhenjiang xu
Dear R users, I am trying to use the following code to make a barchar plot. The bars in the plot turn out to be a little narrow. Is there any way to modify the width of the bars? Thank you! library(lattice) scores = gl(2, 5, label=c('Sensitivity', 'PPV'), length = 100) sequences = gl(5, 1,