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

2011-09-07 Thread zhenjiang xu
or match. The best > > 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 ti

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

2011-09-07 Thread zhenjiang xu
> *** > > to match. E.g., > > 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 &

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

2011-09-07 Thread zhenjiang xu
0.160.030.18 > > system.time(with(dt, rowsum(x, y))) > user system elapsed > 0.360.040.40 > > system.time(with(dt, tapply(x, y, sum))) > user system elapsed > 8.770.339.11 > > HTH, > Dennis > > > On Wed, Sep 7, 2011 at

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

2011-09-07 Thread zhenjiang xu
; [31] "YMR050C" "YOLWTy1-1" "YOL103W-B" "YORWTy1-2" "YOR142W-B" "YPLWTy1-1" [37] "YPL257W-B" "YPRCTy1-2" "YPR137C-B" "YPRWTy1-3" "YPR158W-B" [[4]] [1] "YARCTy1-1" "YA

Re: [R] read.table truncated data?

2011-09-07 Thread zhenjiang xu
(data) > > to see that size is as expected. > > Regards > Petr > > > > > On Thu, Aug 25, 2011 at 11:57 AM, jim holtman > wrote: > > > > > But did you try the following: > > > > > > x <- read.table(, comment.char =

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

2011-09-07 Thread zhenjiang xu
1 at 9:50 AM, Jorge I Velez > 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 > &g

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

2011-09-07 Thread zhenjiang xu
t 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 > > S

[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. T

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 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 > wrote: >> >> Hi R users, >> >> Suppose I

[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 ___

[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
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 > wrote: > > Thanks for your replies. I looked at those lines and didn't spot anything > > unusual. > > > >> tail(a) >

Re: [R] read.table truncated data?

2011-08-25 Thread zhenjiang xu
.0121587 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 wrote: > Hi, > > On Wed, Aug 24, 2011 at 2:18 PM, zhenjiang xu > w

[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
gt; > > Of course this version will have some problems if the names of your list > elements end with digits that you don't want stripped off (but you can work > around that by preprocessing the list names). > > -- > Gregory (Greg) L. Snow Ph.D. > Statistical Data Cent

Re: [R] a question on list manipulation

2011-08-06 Thread zhenjiang xu
hy wrote: > Hi: > > Your clarification suggests Duncan was on the right track, so how about this: > > x <- list(A=c("d", "e", "f"), B=c("d", "e"), C=c("d")) > x2 <- unique(unlist(x)) > w <- lapply(x, functi

Re: [R] a question on list manipulation

2011-08-05 Thread zhenjiang xu
verse the matching, from all the elements to the names of the list. On Fri, Aug 5, 2011 at 12:53 PM, Duncan Murdoch wrote: > On 05/08/2011 12:05 PM, zhenjiang xu wrote: >> >> Hi R users, >> >> I have a list: >> >  x >> $A >> [1] "a"  "b&

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

2011-08-05 Thread zhenjiang xu
help page more carefully. Thanks. On Fri, Aug 5, 2011 at 12:02 PM, Duncan Murdoch 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 >

[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 quic

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 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

[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 l

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 wrote: > On Fri, Apr 15, 2011 at 6:10 PM, zhenjiang xu > wrote: > > Thanks, Dennis! I'll go with it. It's surprising there is no ready wa

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

2011-04-15 Thread zhenjiang xu
fm > x y z > 1 a 1 6 > 2 b 2 NA > 3 c 3 1 > sumdf <- data.frame(x = dfm$x, y = rowSums(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 > wrote: > > Hi all, > > &g

[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 lis

[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] 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] 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 w

[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 HTM

[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
t. On Thu, Apr 29, 2010 at 7:08 PM, Duncan Murdoch wrote: > 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.

[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 a

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

2010-04-23 Thread zhenjiang xu
7;' in mylist() > with appropriate 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 do

[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: Me

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 wrote: > On Wed, Apr 21, 2010 at 8:55 PM, David Winsemius > wrote: > > > > On Apr 21, 2010, at 9:51 PM, zhenjiang xu wrote: > > > >> I tried that.

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

2010-04-23 Thread zhenjiang xu
ley Yield (bushels/acre)",scales = list(x = list(rot = 45), y=list(relation='free', ylim=mylist))) On Thu, Apr 22, 2010 at 7:54 PM, Peter Ehlers wrote: > On 2010-04-21 21:13, zhenjiang xu wrote: > >> R experts, >> >> Is there anyway to reorder inside each

[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 = c(1,6),au

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 wrote: > > On Apr 20, 2010, at 9:46 AM, zhenjiang xu wrote: > > Dear R users, >> >>

[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, label=