Re: [R] date

2010-09-02 Thread Linlin Yan
try to use difftime() instead of as.difftime().

On Thu, Sep 2, 2010 at 10:32 PM, Dunia Scheid dunia.sch...@gmail.com wrote:
 Hello all,

 I've 2 strings that representing the start and end values of a date and
 time.
 For example,
 time1 - c(21/04/2005,23/05/2005,11/04/2005)
 time2 - c(15/07/2009, 03/06/2008, 15/10/2005)
 as.difftime(time1,time2)
 Time differences in secs
 [1] NA NA NA
 attr(,tzone)
 [1] 

 How can i calculate the difference  between this 2 string?

 Regards,
 Dunia

        [[alternative HTML version deleted]]

 __
 R-help@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.


__
R-help@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.


Re: [R] , Updating Table

2010-07-24 Thread Linlin Yan
If I am not wrong, it seems that you want to get factor counts in the
whole scale of data.raw. Maybe you can do that just like this:
table(data.raw)

On Sat, Jul 24, 2010 at 1:44 AM, Marcus Liu marcusliu...@yahoo.com wrote:
 Hi everyone,

 Is there any command for updating table withing a loop?  For instance, at i, 
 I have a table as ZZ = table(data.raw[1:ind[i]]) where ind = c(10, 20, 30, 
 ...).  Then , ZZ will be as follow

 A B C
  3    10   2

 At (i + 1), ZZ = table(data.raw[(ind[i]+1):ind[i+1]])

 A B D
  4    7    8

 Is there any command that can update the table ZZ for each time so that in 
 the above example, ZZ will be

 A B C D
  7    17   2    8

 Thanks.

 liu




        [[alternative HTML version deleted]]


 __
 R-help@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.



__
R-help@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.


Re: [R] getting data from table command

2010-07-10 Thread Linlin Yan
 d - 1:4
 f - c(2,3,3,1)
 rep(d,f)
[1] 1 1 2 2 2 3 3 3 4


On Sat, Jul 10, 2010 at 10:55 PM, nn roh nn.r...@gmail.com wrote:
 Hi,

 I have a question relating to R package

 If i  have the frequencies of data   how i can get the data  as following :

 1 2 3 4      data
 2 3  3 1      frequency

 Which command i can use to get the data set in the above example should be
    1 1  2 2 2 3 3 3  4


 Thanks
 Nada

        [[alternative HTML version deleted]]

 __
 R-help@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.


__
R-help@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.


Re: [R] Creating named lists

2010-03-12 Thread Linlin Yan
Did you mean this:

 n - c('a', 'b')
 structure(list(1, 2), names = n)
$a
[1] 1

$b
[1] 2


On Fri, Mar 12, 2010 at 5:28 PM, Rune Schjellerup Philosof
rphilo...@health.sdu.dk wrote:
 I often find myself making lists similar to this
 list(var1=var1, var2=var2)

 It doesn't seem list has an option, to make it use the name of the
 variable as name in the list.
 Is there another function that does this?

 --
 Med venlig hilsen

 Rune Schjellerup Philosof
 Ph.d-stipendiat, Forskningsenheden for Biostatistik

 Telefon: 6550 3607
 E-mail:  rphilo...@health.sdu.dk
 Adresse: J.B. Winsløwsvej 9, 5000 Odense C

 SYDDANSK UNIVERSITET
 ___
 * Campusvej 55 * 5230 * Odense M * 6550 1000 * www.sdu.dk

 __
 R-help@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.


__
R-help@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.


Re: [R] Group by

2010-03-11 Thread Linlin Yan
 DF
V1  V2   V3
1 10:03:13 3.4 1002
2 10:03:14 5.6 1001
3 10:05:27 7.2  999
4 10:05:33 8.2  998
 DF2 - t(sapply(split(DF[,-1], gsub('(.{5}).*', '\\1:00', DF$V1)), colSums))
 data.frame(V1 = rownames(DF2), DF2)
   V1   V2   V3
10:03:00 10:03:00  9.0 2003
10:05:00 10:05:00 15.4 1997


On Thu, Mar 11, 2010 at 8:16 PM, Henrique Dallazuanna www...@gmail.com wrote:
 Try this:

 DF - read.csv(textConnection(V1,V2,V3
 10:03:13,3.4,1002
 10:03:14,5.6,1001
 10:05:27,7.2,999
 10:05:33,8.2,998), header = TRUE)

 tDates - strptime(DF$V1, %H:%M:%S)
 tDates[[2]] - floor(strptime(DF$V1, %H:%M:%S)[[2]] / 5) * 5

 aggregate(DF[,c('V2', 'V3')],
          list(format(tDates, %H:%M:00)),
          FUN = sum)

 On Thu, Mar 11, 2010 at 6:48 AM, ManInMoon xmoon2...@googlemail.com wrote:

 I have a matrix with a POSIXct as a numeric in the first column.

 I would like to create a new matrix that is grouped by my chosed time
 bars.

 i.e. So I would like to group by hour or day or 5 days, and have all my
 columns be summed or averaged or counted..

 mydata:

 V1,V2,V3
 10:03:13,3.4,1002
 10:03:14,5.6,1001
 10:05:27,7.2,999
 10:05:33,8.2,998

 I want to convert this into say 5 minutes bars and sum columns

 mynewdata:

 V1,V2,V3
 10:00:00,9.0,2003
 10:05:00,15.4,1997


 How can I do this?
 --
 View this message in context: 
 http://n4.nabble.com/Group-by-tp1588694p1588694.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@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.




 --
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O

 __
 R-help@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.


__
R-help@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.


Re: [R] Define column names to a series of data.frames

2010-03-11 Thread Linlin Yan
It seems that the names of original data frames have not changed in
this way. I guess textConnection() could help, like this:

for (name in objects(pattern = df[0-9]))
eval(parse(textConnection(paste('names(', name, ') -
column_names'

On Thu, Mar 11, 2010 at 9:25 PM, Henrique Dallazuanna www...@gmail.com wrote:
 You can try this:

 lapply(lapply(ls(pattern = 'DF[0-9]'), get),
       'names-', c(SDev,PC1, PC2, PC3, PC4, PC5, PC6))

 On Thu, Mar 11, 2010 at 9:33 AM, Nikos Alexandris
 nikos.alexand...@felis.uni-freiburg.de wrote:
 Greets to the list!

 I am aware that this topic has been discussed several times. And I've
 read quite some related posts [1]. Yet, can't seem to give a solution to
 my problem.

 I have 6 data frames consisting of 6 rows x 7 columns put together from
 other data.frames.

 Something like:

   a b c d e f g
 v1 # # # # # # #
 v2 # # # # # # #
 v3 # # # # # # #
 v4 # # # # # # #
 v5 # # # # # # #
 v6 # # # # # # #


 I want to give the following column names to each data.frame: (SDev,
 PC1, PC2, PC3, PC4, PC5, PC6)

 Works fine for one data.frame:
 column_names - c(SDev, PC1, PC2, PC3, PC4, PC5, PC6)
 names( df1 ) - column_names

 How is it to be done at once for all data.frames that the function
 objects(pattern = SomePattern) can find?

 I've tried several things with assign, get, paste, for but I am not
 getting anywhere. I need to integrate this in a function that can handle
 lot's of data.frames and not only 6.

 Thank you, Nikos


 ---
 [1] I am stuck on this post:
 http://www.mail-archive.com/r-h...@stat.math.ethz.ch/msg32063.html.

 It reads:

 dframes - c(a,b,c)
 cols - c(one,two)
 df - data.frame(11:20, 21:30)
 names(df) - cols
 assign(dframes[2], df)

 Can't understand the logic behind the [2].

 __
 R-help@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.




 --
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O

 __
 R-help@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.


__
R-help@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.


Re: [R] Define column names to a series of data.frames

2010-03-11 Thread Linlin Yan
Amazing! I haven't seen usage of calling `names-` like this before.
Thanks so much!

On Thu, Mar 11, 2010 at 9:50 PM, Henrique Dallazuanna www...@gmail.com wrote:
 Yes, just in the list.
 If they want change the name in Environment GlobalEnv:

  for(i in ls(pattern = DF[0-9]))
       assign(i, `names-`(get(i), c(SDev,PC1, PC2, PC3,
 PC4, PC5, PC6)), globalenv())

 --
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O


__
R-help@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.


Re: [R] How to match vector with a list ?

2010-03-08 Thread Linlin Yan
Maybe you can create a helper vector first:
 helper - structure(names = unlist(j), rep(names(j), sapply(j, length)))
 helper
   acbd
j1 j1 j2 j2
 helper[i]
   aabbbccd
j1 j1 j2 j2 j2 j1 j1 j2

On Sat, Mar 6, 2010 at 1:42 AM, Carlos Petti carlos.pe...@gmail.com wrote:
 Dear list,

 I have a vector of characters and a list of two named elements :

 i - c(a,a,b,b,b,c,c,d)

 j - list(j1 = c(a,c), j2 = c(b,d))

 I'm looking for a fast way to obtain a vector with names, as follows :

 [1] j1 j1 j2 j2 j2 j1 j1 j2

 I used :

 match - lapply(j, function (x) {which(i %in% x)})
 k - vector()
 for (y  in 1:length(match)) {
 k[match[[y]]] - names(match[y])}
 k
 [1] j1 j1 j2 j2 j2 j1 j1 j2

 But, I think a better way exists ...

 Thanks in advance,
 Carlos

        [[alternative HTML version deleted]]

 __
 R-help@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.


__
R-help@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.


Re: [R] Average regions of non-zeros

2010-03-08 Thread Linlin Yan
Nice shot of cumsum(). Just improve it a little:

 x - c(0,0,1,2,3,0,0,4,5,6)
 x.groups - split(x, (x != 0) * cumsum(x == 0))[-1]
 x.groups
$`2`
[1] 1 2 3

$`4`
[1] 4 5 6

 lapply(x.groups, mean)
$`2`
[1] 2

$`4`
[1] 5

On Mon, Mar 8, 2010 at 11:02 AM, jim holtman jholt...@gmail.com wrote:
 Try this:

 x - c(0,0,1,2,3,0,0,4,5,6)
 # partition the data
 x.p - split(x, cumsum(x == 0))
 # now only process groups  1
 x.mean - lapply(x.p, function(a){
 +     if (length(a) == 1) return(NULL)
 +     return(list(grp=tail(a, -1), mean=mean(tail(a, -1
 + })
 # now only return the real values
 x.mean[unlist(lapply(x.mean, length) != 0)]
 $`2`
 $`2`$grp
 [1] 1 2 3
 $`2`$mean
 [1] 2

 $`4`
 $`4`$grp
 [1] 4 5 6
 $`4`$mean
 [1] 5



 On Sun, Mar 7, 2010 at 9:48 PM, Daren Tan dare...@hotmail.com wrote:


 x - c(0,0,1,2,3,0,0,4,5,6)



 How to identify the regions of non-zeros and average c(1,2,3) and c(4,5,6)
 to get 2 and 5.



 Thanks



 _
 Hotmail: Trusted email with Microsoft’s powerful SPAM protection.

        [[alternative HTML version deleted]]


 __
 R-help@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.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




 --
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390

 What is the problem that you are trying to solve?

        [[alternative HTML version deleted]]


 __
 R-help@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.



__
R-help@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.


Re: [R] Reducing a matrix

2010-02-27 Thread Linlin Yan
Try this:
df[!duplicated(df[,'x']),]

On Sun, Feb 28, 2010 at 8:56 AM, Juliet Ndukum jpnts...@yahoo.com wrote:
 I wish to rearrange the matrix, df, such that all there are not repeated x 
 values. Particularly, for each value of x that is reated, the corresponded y 
 value should fall under the appropriate column.  For example, the x value 3 
 appears 4 times under the different columns of y, i.e. y1,y2,y3,y4. The 
 output should be such that for the lone value of 3 selected for x, the 
 corresponding row entries with be 7 under column y1, 16 under column y2, 12 
 under column y3 and 18 under column y4. This should work for  the other rows 
 of x with repeated values.
 df
   x y1 y2 y3 y4
 1   3  7 NA NA NA
 2   3 NA 16 NA NA
 3   3 NA NA 12 NA
 4   3 NA NA NA 18
 5   6  8 NA NA NA
 6  10 NA NA  2 NA
 7  10 NA 11 NA NA
 8  14 NA NA NA  8
 9  14 NA  9 NA NA
 10 15 NA NA NA 11
 11 50 NA NA 13 NA
 12 50 20 NA NA NA

 The output should be:

   x y1 y2 y3 y4
 1   3  7 16 12 18
 2   6  8 NA NA NA
 3  10 NA 11  2 NA
 4  14 NA 9 NA  8
 5 15 NA NA NA 11
 6 50 20 NA 13 NA

 Can any write for me a code that would produce these results.
 Thank you in advance for your help.

 JN



        [[alternative HTML version deleted]]

 __
 R-help@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.


__
R-help@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.


Re: [R] question to make a vector without loop

2010-02-26 Thread Linlin Yan
For general purpose of recursion formula, you could do it like this:
 make.vector - function(w, n, a, b) c(w, sapply(1:(n-1), function(x) w - w 
 * a / (b + x)))
 make.vector(w = 1, n = 4, a = 24, b = 1)
[1]   1  12  96 576

On Fri, Feb 26, 2010 at 11:23 PM,  khaz...@ceremade.dauphine.fr wrote:
 Hello all,

 I want to define a vector like w[k+1]=w[k]*a/(b+k) for k=1,...,N-1 without
 use loop. Is it posible to do in R?

 Regards

 khazaei

 __
 R-help@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.


__
R-help@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.


Re: [R] replicate matrix

2010-02-20 Thread Linlin Yan
You can just rep() it, and c() with extra data, and then matrix() it again:
 m - matrix(c(1,4,3,6),2)
 matrix(c(rep(m, 3), c(2, 5)), nrow(m))
 [,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,]1313132
[2,]4646465

On Sun, Feb 21, 2010 at 10:58 AM, wendy wendy.q...@utoronto.ca wrote:

 Hi all,

 I have a matrix, for example
     [,1] [,2]
 [1,]  1    3
 [2,]  4    6

 I want to replicate the matrix twice and add an extra column at the end,
 which is
     [,1] [,2] [,3] [,4] [,5] [,6] [,7]
 [1,]  1    3     1    3     1    3    2
 [2,]  4    6     4    6     4    6    5

 I found 'rep' only works for vector. Does anyone know how to replicate a
 matrix, and append the matrix?

 Thank you in advance,
 Wendy


 --
 View this message in context: 
 http://n4.nabble.com/replicate-matrix-tp1563337p1563337.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@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.


__
R-help@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.


Re: [R] How to store an array like this?

2010-02-19 Thread Linlin Yan
It's not an array, but a list:
lapply(2:n, function(x) matrix(1:x^2,x))

On Sat, Feb 20, 2010 at 3:17 PM, song song rprojecth...@gmail.com wrote:
 maybe its not an array

 like

 m[1]=matrix(1:4,2,2)
 m[2]=matrix(1:9,3,3)
 .
 .
 .
 m[k]=matrix(1:k^2,k,k)

 likes

 for (k in 1:n){
  s=matrix(1:k^2,k,k)
 }

 how to store s like s[1], s[2] ... so that I can use it in other place?

 thanks!

        [[alternative HTML version deleted]]

 __
 R-help@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.


__
R-help@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.


Re: [R] Printing 2 digits after decimal point

2010-02-15 Thread Linlin Yan
format(x, nsmall = 2)

On Mon, Feb 15, 2010 at 5:41 PM, t.wun...@stud.uni-heidelberg.de wrote:

 Hi there,

 i'm not getting along with the following problem.
 I'd like to print a real number, e.g.
 x - 12.3
 with exactly two digits after the decimal point, e.g.
 12.30
 I've tried the whole format(), formatC() and prettyNum() functions but
 did not have any success with it.
 This should work with all real numbers, in case even with 0.0 (- 0.00).
 For cracks this thing is pretty sure obvious, but I've spent the whole 
 morning with it.

 Please help me!

 Thanks a lot,
 Tom

 __
 R-help@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.

__
R-help@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.


Re: [R] How to: highlight R syntax on webpages ?

2010-02-12 Thread Linlin Yan
To achieve this goal, it seems there are several ways, such as
WP-Syntax (http://wordpress.org/extend/plugins/wp-syntax/),
SyntaxHighlighter2
(http://mohanjith.com/2009/03/syntaxhighlighter2.html), etc. However,
these plugins seem not support R language by default, so you may have
to write some code to declare the keywords and functions for R. And
also you can write another plugin by yourself if you like, it's not so
difficult.

On Sat, Nov 21, 2009 at 2:26 AM, Tal Galili tal.gal...@gmail.com wrote:
 My question if in the Subject, but if to extend: I am specifically curious
 about WordPress blogs. But any solution will give me a lead.

 Thanks,
 Tal


 --
 Contact me: tal.gal...@gmail.com |  972-52-7275845
 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
 www.r-statistics.com/ (English)

        [[alternative HTML version deleted]]

 __
 R-help@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.


__
R-help@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.


Re: [R] How to: highlight R syntax on webpages ?

2010-02-12 Thread Linlin Yan
I have saw it now. Thank you for your excellent works.

On Fri, Feb 12, 2010 at 9:15 PM, Tal Galili tal.gal...@gmail.com wrote:
 Hi Linlin,
 I am afraid I wasn't clear.
 In my post I fixed the current WP-Syntax plugin so it WILL support the R
 syntax :)
 The link to the article is:
 http://www.r-statistics.com/2010/02/r-syntax-highlight-on-your-blog-a-wordpress-plugin/

 Best,
 Tal


 Contact
 Details:---
 Contact me: tal.gal...@gmail.com |  972-52-7275845
 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
 www.r-statistics.com (English)
 -
__
R-help@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.


Re: [R] apply command

2010-01-19 Thread Linlin Yan
I guess that the matrix dimension changed because matrix in R are
filled by columns. Since you try:
apply(b, 1, function(y) sort(y, na.last=F))
The second parameter make it scan matrix b row by row but store result
by columns, which make the result be a matrix transposed.
If you try:
apply(b, 2, function(y) sort(y, na.last=F))
The second parameter means scan column by column, and the result
matrix will have the same dimension with origin.

On Tue, Jan 19, 2010 at 6:31 PM, Tal Galili tal.gal...@gmail.com wrote:
 Hello Marco

 What I would do, is use t to transpose the matrix.
 Why it is that apply switches the matrix, is beyond my knowledge - and I
 would love to read more informed replies.

 Tal



 Contact
 Details:---
 Contact me: tal.gal...@gmail.com |  972-52-7275845
 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
 www.r-statistics.com/ (English)
 --




 On Tue, Jan 19, 2010 at 12:27 PM, marco salvini 
 marco.salv...@gmail.comwrote:

 Can you please help on the issue?
 I using the apply command on a matrix below the example:

 Create a vector
 x =c(5, 3, 2:4, NA, 7, 3, 9, 2, 1, 5)

 create a matrix of 2 rows by 6 columns
  b=matrix(x, 2,6)
  print(b)
     [,1] [,2] [,3] [,4] [,5] [,6]
 [1,]    5    2    4    7    9    1
 [2,]    3    3   NA    3    2    5

 using the command apply
  print(apply(b, 1, function(y) sort(y, na.last=F)))

 the output is a matrix of 6 rows by 2 columns.
      [,1] [,2]
 [1,]    1   NA
 [2,]    2    2
 [3,]    4    3
 [4,]    5    3
 [5,]    7    3
 [6,]    9    5

 As you can see in the example I start with a matrix of (2 by 6) and the
 output of apply is a mtraxi of (6 by 2).
 This is very strange because I was expecting as output a matrix of the same
 dim (2 by 6) of the input matrix. I can solve this issues using an if
 statment on the dim of the matrix but if I am using a square matrix I am
 not
 able to control if the result of the apply is correct.

 Do anyone find a solution to this issue?
 thanks
 Marco

        [[alternative HTML version deleted]]

 __
 R-help@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.


        [[alternative HTML version deleted]]

 __
 R-help@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.


__
R-help@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.


Re: [R] as.Date question

2009-12-24 Thread Linlin Yan
I am afraid that although in same literally, they are indeed different
functions: as.Date.POSIXct and as.Date.POSIXlt. But I am not sure why
they are designed like this, which causes the confusion as you
mentioned.

On Thu, Dec 24, 2009 at 11:02 PM, MAL diver...@univecom.ch wrote:
 Mark, not sure that's the answer.

 Usually one has x=y -- f(x)=f(y)

 which doesn't seem to hold here (put x=zzz1, y=zzz2, f=as.Date()).

 Or do I overlook something?


 - Original Message - From: Marek Janad marek.ja...@gmail.com
 To: r-help@r-project.org
 Sent: Thursday, December 24, 2009 00:08
 Subject: Re: [R] as.Date question


 Look at documentation

 ?as.Date

 as.Date first represents time in UTC, what gives:

 as.POSIXlt(zzz1, tz=UTC)

 HTH

 2009/12/20 MAL diver...@univecom.ch:

 All!

 This piece of code:

 zzz1 - as.POSIXct(1999-03-18, tz=CET)
 zzz2 - as.POSIXlt(1999-03-18, tz=CET)
 zzz1 == zzz2
 as.Date(zzz1)
 as.Date(zzz2)

 yields TRUE for zzz1==zzz2, but the two dates returned by as.Date are
 different:

 as.Date(zzz1)

 [1] 1999-03-17

 as.Date(zzz2)

 [1] 1999-03-18

 I'm using R 2.10.0.

 Would be glad for any clarifications. Thanks!

 __
 R-help@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.




 --
 Marek

 __
 R-help@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.

 __
 R-help@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.


__
R-help@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.


Re: [R] How to find the significant digits of a number?

2009-12-16 Thread Linlin Yan
Try this:
 f - function(x) length(gregexpr([[:digit:]], as.character(x))[[1]])
 f(3.14)
[1] 3
 f(3.1415)
[1] 5
 f(3.14159265)
[1] 9

On Wed, Dec 16, 2009 at 1:39 PM, Xiang Wu xiang@gmail.com wrote:
 Is there a function in R that could find the significant digit of a specific
 number? Such as for 3.1415, return '5'?

 Thanks in advance.

__
R-help@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.


Re: [R] Is there lazy copy in R?

2009-12-14 Thread Linlin Yan
It means that R does have the lazy copy mechanism, which I didn't
know, and I think it can be very useful to make R running more
quickly.

On Tue, Dec 15, 2009 at 12:15 PM, Peng Yu pengyu...@gmail.com wrote:
 a=1:10
 b=a
 a=1:10
 tracemem(a)# I assume the following is address 'a' points to
 [1] 0x05cf2798
 b=a
 b[1]=1
 tracemem[0x05cf2798 - 0x05cf2750]:
 tracemem[0x05cf2750 - 0x05ed8ba0]:

 I don't understand what these addresses mean. Would you please help me
 understand it?

__
R-help@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.


Re: [R] Removing objects from a list based on nrow

2009-11-29 Thread Linlin Yan
Try these:
sapply(lst, nrow) # get row numbers
which(sapply(lst, nrow)  3) # get the index of rows which has less than 3 rows
lst - lst[-which(sapply(lst, nrow)  3)] # remove the rows from the list

On Sun, Nov 29, 2009 at 4:36 PM, Tim Clark mudiver1...@yahoo.com wrote:
 Dear List,

 I have a list containing data frames of various numbers of rows.  I need to 
 remove any data frame that has less than 3 rows.  For example:

 df1-data.frame(letter=c(A,B,C,D,E),number=c(1,2,3,4,5))
 df2-data.frame(letter=c(A,B),number=c(1,2))
 df3-data.frame(letter=c(A,B,C,D,E),number=c(1,2,3,4,5))
 df4-data.frame(letter=c(A,B,C,D,E),number=c(1,2,3,4,5))

 lst-list(df1,df2,df3,df4)

 How can I determine that the second object (df2) has less than 3 rows and 
 remove it from the list?

 Thanks!

 Tim




 Tim Clark
 Department of Zoology
 University of Hawaii

 __
 R-help@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.


__
R-help@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.


Re: [R] column of dates into time series

2009-11-29 Thread Linlin Yan
There is no year() function. Maybe you can try format() instead.

On Sun, Nov 29, 2009 at 8:44 PM, DispersionMap frenc...@btinternet.com wrote:

 i have a column of dates in this format:

 data[,Raised.Date] - as.Date(data[,Raised.Date], %d/%m/%Y);
 data[1:10,Raised.Date]
 [1] 2006-07-07 2006-07-07 2006-04-03 2006-04-03 2006-04-03
 2006-04-03 2006-04-03 2006-04-03 2006-04-03 2006-04-03

 I can turn them into months like this...

 Month-months(data[,Raised.Date])
 Month[1:10]
 [1] July  July  April April April April April April April
 April


 But i also want to turn them into years (and also weeks later on), so tried
 this...

 Year-year(data[,Raised.Date])
 Error: could not find function year


 thanks.
 --
 View this message in context: 
 http://n4.nabble.com/column-of-dates-into-time-series-tp930699p930699.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@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.


__
R-help@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.


Re: [R] Removing objects from a list based on nrow

2009-11-29 Thread Linlin Yan
Thank Jim! You are right. I didn't notice the case of none of rows
match the condition.

On Sun, Nov 29, 2009 at 10:10 PM, jim holtman jholt...@gmail.com wrote:
 One thing to be careful of is if no dataframe have less than 3 rows:

 df1-data.frame(letter=c(A,B,C,D,E),number=c(1,2,3,4,5))
 df2-data.frame(letter=c(A,B),number=c(1,2))
 df3-data.frame(letter=c(A,B,C,D,E),number=c(1,2,3,4,5))
 df4-data.frame(letter=c(A,B,C,D,E),number=c(1,2,3,4,5))

 lst-list(df1,df3,df4)
 lst
 [[1]]
  letter number
 1      A      1
 2      B      2
 3      C      3
 4      D      4
 5      E      5

 [[2]]
  letter number
 1      A      1
 2      B      2
 3      C      3
 4      D      4
 5      E      5

 [[3]]
  letter number
 1      A      1
 2      B      2
 3      C      3
 4      D      4
 5      E      5

 lst[-which(sapply(lst, nrow)  3)]
 list()


 Notice the list is now empty.  Instead use:

 lst[sapply(lst, nrow) =3]
 [[1]]
  letter number
 1      A      1
 2      B      2
 3      C      3
 4      D      4
 5      E      5

 [[2]]
  letter number
 1      A      1
 2      B      2
 3      C      3
 4      D      4
 5      E      5

 [[3]]
  letter number
 1      A      1
 2      B      2
 3      C      3
 4      D      4
 5      E      5


 On Sun, Nov 29, 2009 at 3:43 AM, Linlin Yan yanlinli...@gmail.com wrote:
 Try these:
 sapply(lst, nrow) # get row numbers
 which(sapply(lst, nrow)  3) # get the index of rows which has less than 3 
 rows
 lst - lst[-which(sapply(lst, nrow)  3)] # remove the rows from the list

 On Sun, Nov 29, 2009 at 4:36 PM, Tim Clark mudiver1...@yahoo.com wrote:
 Dear List,

 I have a list containing data frames of various numbers of rows.  I need to 
 remove any data frame that has less than 3 rows.  For example:

 df1-data.frame(letter=c(A,B,C,D,E),number=c(1,2,3,4,5))
 df2-data.frame(letter=c(A,B),number=c(1,2))
 df3-data.frame(letter=c(A,B,C,D,E),number=c(1,2,3,4,5))
 df4-data.frame(letter=c(A,B,C,D,E),number=c(1,2,3,4,5))

 lst-list(df1,df2,df3,df4)

 How can I determine that the second object (df2) has less than 3 rows and 
 remove it from the list?

 Thanks!

 Tim




 Tim Clark
 Department of Zoology
 University of Hawaii

 __
 R-help@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.


 __
 R-help@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.




 --
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390

 What is the problem that you are trying to solve?


__
R-help@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.


Re: [R] List Name help

2009-11-23 Thread Linlin Yan
On Tue, Nov 24, 2009 at 1:01 AM, Henrique Dallazuanna www...@gmail.com wrote:
 Try this:

 test[grep(d2, names(test))]

Or it can be simply like this:

test[names(test) == d2]

 On Mon, Nov 23, 2009 at 2:53 PM, Rajasekaramya ramya.vict...@gmail.com 
 wrote:

 Hi There,

 I have a named List object.I want to access all the list elements that has
 the same name
 for example
 The List
 test - list()
 $d2
 v1 v2 v3 v4
 1 2 3 4 5

 $d2
 v1 v2 v3 v4
 1 2 3 4 5

 $d3
 v1 v2 v3 v4
 8 9 19 10

 $d1
 v1 v2 v3 v4
 12 14 15 16

 so if i say test[[d2]] or test[d2] i should get the first two that
 matches the name rite but i am not getting them jus getting the first one.

 Any suggestions on it

 Ramya






 --
 View this message in context: 
 http://old.nabble.com/List-Name-help-tp26481873p26481873.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@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.




 --
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O

 __
 R-help@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.


__
R-help@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.


Re: [R] Removing + and ? signs

2009-11-22 Thread Linlin Yan
Try this:
gsub([?],  , x)

On Mon, Nov 23, 2009 at 7:01 AM, Steven Kang stochastick...@gmail.com wrote:
 Hi all,


 I get an error message when trying to replace *+* or *?* signs (with empty
 space) from a string.

 x - asdf+,jkl?

 gsub(?,  , x)


 Error message:

 Error in
 gsub(?,  , x) :
  invalid regular expression '?'
 In addition: Warning message:
 In gsub(?,  , x) :
  regcomp error:  'Invalid preceding regular expression'

 Your expertise in resolving this issue would be appreciated.

 Thanks.



 Steven

        [[alternative HTML version deleted]]

 __
 R-help@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.


__
R-help@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.


Re: [R] [Rd] How to generate dependency file that can be used by gnu make?

2009-11-16 Thread Linlin Yan
I don't think this function is same as gcc's option -MM. Because gcc
checks pre-compile command #include, in which the filename can be
fetched definitely. But in your scenario, the filename may be from
some variables, which can not be determined by the R script only.
Maybe you can write a tool by yourself to parse the R syntax to
resolve your problem.

On Tue, Nov 17, 2009 at 11:51 AM, Peng Yu pengyu...@gmail.com wrote:
 On Sun, Nov 15, 2009 at 8:45 PM, Peng Yu pengyu...@gmail.com wrote:
 gcc has options like -MM, which can generate the dependence files for
 a C/C++ file that I can be used by gnu make. I'm wondering if there is
 a tool that can generate dependence file for an R script.

 For example, I have an R script test.R

 #test.R
 load('input.RData')
 save.image('output.RData')


 I want to generate a dependence file like the following. Is there a
 tool to do so?

 output.RData:test.R input.RData

 Is there a way to automatically generate the output files that depends
 on an R script and the input files and sourced files that are depended
 by an R script? I don't see this option in R. But I wish this can be
 implemented in future version of R.

 __
 r-de...@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel


__
R-help@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.


Re: [R] How to get the string '\'?

2009-11-15 Thread Linlin Yan
Regular expression needs double the '\' again, so try this:
gsub('/','',string)

On Mon, Nov 16, 2009 at 7:35 AM, Peng Yu pengyu...@gmail.com wrote:
 My question was from replacing a pattern by '\\'. How to replace '/'
 in string by '\'?

 string='abc/efg'
 gsub('/','\\',string)
 __
 R-help@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.


__
R-help@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.


Re: [R] pairs

2009-11-15 Thread Linlin Yan
Hope this help:

 m - matrix(c(2,1,3,9,5,7,7,8,1,8,6,5,6,2,2,7),4,4)
 p - c(2, 6)

 apply(m == p[1], 1, any)  apply(m == p[2], 1, any)
[1]  TRUE FALSE  TRUE FALSE

If you want the number of rows which contain the pair, sum() could be used:

 sum(apply(m == p[1], 1, any)  apply(m == p[2], 1, any))
[1] 2

On Mon, Nov 16, 2009 at 6:26 AM, cindy Guo cindy.g...@gmail.com wrote:
 Hi, All,

 I have an n by m matrix with each entry between 1 and 15000. I want to know
 the frequency of each pair in 1:15000 that occur together in rows. So for
 example, if the matrix is
 2 5 1 6
 1 7 8 2
 3 7 6 2
 9 8 5 7
 Pair (2,6) (un-ordered) occurs together in rows 1 and 3. I want to return
 the value 2 for this pair as well as that for all pairs. Is there a fast way
 to do this avoiding loops? Loops take too long.

 Thank you,

 Cindy

        [[alternative HTML version deleted]]

 __
 R-help@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.


__
R-help@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.


Re: [R] How to strip everything after second whitespace?

2009-11-06 Thread Linlin Yan
Try this:
 gsub(([a-z]*\\s[a-z]*).*, \\1, nam)
[1] Smith John  Smith David Smith Ryan

On Fri, Nov 6, 2009 at 4:11 PM, johannes rara johannesr...@gmail.com wrote:
 How to split everything after second whitespace char using regular
 expression? I want to remove A, B, C and D from these names:

 nam - c(Smith John A, Smith David B C, Smith Ryan C D)

 Thanks,
 Johannes

 __
 R-help@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.


__
R-help@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.


Re: [R] How to exclude certain columns by column names?

2009-11-02 Thread Linlin Yan
Try this:
 x[, colnames(x) != 'a']
[1] 3 4

On Tue, Nov 3, 2009 at 9:31 AM, Peng Yu pengyu...@gmail.com wrote:
 I can exclude columns by column number using '-'. But I wondering if
 there is an easy way to exclude some columns by column names.

 x=cbind(c(1,2),c(3,4))
 x
     [,1] [,2]
 [1,]    1    3
 [2,]    2    4
 colnames(x)=c('a','b')
 x
     a b
 [1,] 1 3
 [2,] 2 4
 x[,-'a']
 Error in -a : invalid argument to unary operator
 x[,-1]
 [1] 3 4

 __
 R-help@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.


__
R-help@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.


Re: [R] exact string match?

2009-10-30 Thread Linlin Yan
How about using operator ==

On Sat, Oct 31, 2009 at 5:00 AM, bamsel benam...@gmail.com wrote:

 Dear R users:
 I need to compare character strings stored in 2 separate data frames. I need
 an exact match, so finding a in animal is no good.
 I've tried regexpr, match, and grepl, but to no avail.
 Anybody know how to accomplish this?
 Ben
 --
 View this message in context: 
 http://old.nabble.com/exact-string-match--tp26136677p26136677.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@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.


__
R-help@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.


Re: [R] how to do this?

2009-09-11 Thread Linlin Yan
Try this:
 y[matrix(c(seq_along(x), x), ncol = 2)]
[1]  2 16 12

On Fri, Sep 11, 2009 at 4:17 PM, Luca Braglia brag...@poleis.eu wrote:
 Hello R-users

 I have a situation like this

 x=c(1,3,2)

 y=data.frame(a=1:3, b=4:6, c=7:9)*2

 So we have

 t(t(x))
     [,1]
 [1,]    1
 [2,]    3
 [3,]    2

 And

 y
  a  b  c
 1 2  8 14
 2 4 10 16
 3 6 12 18

 I would like to obtain a vector with number taken from the data.frame: x is 
 needed as row index

 With c(1,3,2), in this case the ouput should be

 2
 16
 12

 I've tried a little bit with apply, but unsuccessfully.

 Thank you

 __
 R-help@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.


__
R-help@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.


Re: [R] NotePad++ Syntax file

2009-08-10 Thread Linlin Yan
I think NppToR may be a good choice.
http://sourceforge.net/projects/npptor/

On Tue, Aug 11, 2009 at 6:37 AM, Farley, Robertfarl...@metro.net wrote:


 Does anyone have an R Syntax Highlighting file {userDefineLang.xml} for 
 NotePad++??  I've started one, but I'm not so happy with it.




 Robert Farley
 Metro
 1 Gateway Plaza
 Mail Stop 99-23-7
 Los Angeles, CA 90012-2952
 Voice: (213)922-2532
 Fax:    (213)922-2868
 www.Metro.net



        [[alternative HTML version deleted]]

 __
 R-help@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.


__
R-help@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.


Re: [R] vector

2009-07-29 Thread Linlin Yan
rep(A, each=2)

On Thu, Jul 30, 2009 at 12:15 AM, Inchallah
Yarabinchallahya...@yahoo.fr wrote:
 Hi ,

 i have a vector A=(a1,a2,a3,a4) and i want to create another vector 
 B=(a1,a1,a2,a2,a3,a3,a4,a4) !!!
 i know that it is simple but i begin with R so i nned your help!!

 thank you for your help !!!



        [[alternative HTML version deleted]]

 __
 R-help@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.


__
R-help@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.


Re: [R] Function to standardize matriz?

2009-07-29 Thread Linlin Yan
Did you mean this:

 m - matrix(1:12, 3, 4)
 m / max(m)
   [,1]  [,2]  [,3]  [,4]
[1,] 0.0833 0.333 0.583 0.833
[2,] 0.1667 0.417 0.667 0.917
[3,] 0.2500 0.500 0.750 1.000

On Thu, Jul 30, 2009 at 12:52 PM, Samsamanta.fernan...@gmail.com wrote:
 Hi,
 this is probably a very basic question but I'm just learning R and i
 cannot find  a function to standardize a data matrix..
 I'll be grateful for any tips or help you can provide me.

 Thank you very much!

 __
 R-help@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.


__
R-help@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.


Re: [R] Lists

2009-07-25 Thread Linlin Yan
How about like this:

for (i in seq_along(a)) {
  result - as.list(a[1:i])
  cat(iterator, i, :\n)
  print(result)
}

On Sat, Jul 25, 2009 at 6:48 AM, Alberto Lora Malbertolo...@gmail.com wrote:
 Hi Everybody

 I have the following problem

 suppose that we

 a-c(uno,dos,tres)

 I am working with a while cycle and the idea is in each iteration adding an
 item to a list

 In the first iteration the resultshould be:
 [[1]]
 [1] uno

 In the second
 [[1]]
 [1] uno
 [[2]]
 [1] dos

 And the final result
 [[1]]
 [1] uno
 [[2]]
 [1] dos
 [[3]]
 [1] tres

 How can I do that
 Thx again
 --
 Alberto

        [[alternative HTML version deleted]]

 __
 R-help@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.


__
R-help@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.


Re: [R] How to append to a list dynamically?

2009-06-17 Thread Linlin Yan
Function parameters in R are passed by value, not by reference. In
order to resolve it, just remove clusters from the parameter list,
and use clusters[i] - ... to change the value of global variable.

On Wed, Jun 17, 2009 at 7:52 PM, Nick Angelounikola...@yahoo.com wrote:

 Hi,

 I have a problem with dynamic appending to a list. Here is the list
 variable:


 clusters - vector(list, 0)


 I extended in the function below:


 cluster - function (pair, clusters)
 {
  found - FALSE
  for (i in length(clusters))
  {
    if (length(intersect(pair, clusters[i]))  0)
    {
     clusters[i] - union(clusters[i], pair)
     found - TRUE
    }
  }
  if (!found)
  {
   clusters - list(clusters, as.vector(pair))
  }
 }


 The function is executed in a loop:


 for (i in 1:nrow(adjMatrix))
 {
 for (j in 1:nrow(adjMatrix))
 {
  if ((i != j)  adjMatrix[i,j] 0) # the matrix element has to be non-zero
 in order to be clustered
  {
    cat(rownames(adjMatrix)[i], colnames(adjMatrix)[j], \n)
    cluster(as.vector(c(rownames(adjMatrix)[i], colnames(adjMatrix)[j])),
 clusters)
  }
 }
 }


 But the list variable remains empty (i.e. length(clusters) = 0) even though
 it should not. Somehow the dynamic extension of the list does not work in
 this case. Any suggestions?

 Best regards,

 Nick
 --
 View this message in context: 
 http://www.nabble.com/How-to-append-to-a-list-dynamically--tp24071794p24071794.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@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.


__
R-help@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.


Re: [R] how to get output from a nested loop

2009-06-10 Thread Linlin Yan
How about like this:
 t1 - data.frame(row.names=c('c1','c2','c3','c4'), mk1=c(1,1,0,0), 
 mk2=c(0,0,0,1), mk3=c(1,1,1,1), mk4=c(0,0,0,0), mk5=c(0,0,0,1), S=c(4,5,3,2))
 t1
   mk1 mk2 mk3 mk4 mk5 S
c1   1   0   1   0   0 4
c2   1   0   1   0   0 5
c3   0   0   1   0   0 3
c4   0   1   1   0   1 2
 apply(combn(1:5, 2), 2, function(x) t1[,c(x[1], 6, x[2])])
[[1]]
   mk1 S mk2
c1   1 4   0
c2   1 5   0
c3   0 3   0
c4   0 2   1
... ...

On Wed, Jun 10, 2009 at 1:10 PM, Scott Hermannsherm...@bses.org.au wrote:
 Dear all,

 I imagine that this is a trival question, but it has perplexed for most of 
 the day.  Any help would be greatly appreciated.

 Below is an example of what I'm trying to do.

 Essentially I want to produce all unique 1 x 1 combinations of certain 
 columns from a dataframe, and join these to other columns from the same 
 dataframe.  I'm having problems with the nested loop as I can only output 
 data from the last cycle of the loop.  I realise that the problem is with 
 the st1[[i]] but I'm not sure how to define it differently.

 ##I want to make a list file of all 1x1 combinations of mk columns, and add 
 clone and S to these combinations.

 clone-c(c1,c2,c3,c4)
 mk1-c(1,1,0,0)
 mk2-c(0,0,0,1)
 mk3-c(1,1,1,1)
 mk4-c(0,0,0,0)
 mk5-c(0,0,0,1)
 S-c(4,5,3,2)
 t1-as.data.frame(cbind(clone,mk1,mk2,mk3,mk4, mk5,S))
 row.names(t1)-t1$clone
 t1-t1[,-1]
 t1

 ###A nested loop.  I'm trying to get all combinations of columns 1:5 and join 
 each of them with column 7.

 st1 - list()
  for(i in 1:4) {
   for(j in (i+1):5){
       st1[[i]] - cbind(t1[,c(i,6)],t1[,j])
       }
       }
  st1

 Thanks for your help,

 Scott
 BSES Limited Disclaimer

 

 This email and any files transmitted with it are confide...{{dropped:13}}

 __
 R-help@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.


__
R-help@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.


Re: [R] Help with if statements

2009-06-09 Thread Linlin Yan
Try this:
for (i in 1:dim(ALLRESULTS)[1]) {
  ALLRESULTS[i,23] - length(ALLRESULTS[i,][ALLRESULTS[i,16:22] = 0.05])
}

On Wed, Jun 10, 2009 at 12:17 AM, Amit Patelamitrh...@yahoo.co.uk wrote:

 Hi
 I am trying to create a column in a data frame which gives a sigificane score 
 from 0-7. It should read values from 7 different colums and add 1 to the 
 counter if the value is =0.05. I get an error message saying

 Error in if (ALLRESULTS[i, 16] = 0.05) significance_count = 
 significance_count +  :
  missing value where TRUE/FALSE needed

 The script is included below

 it works if i convert the NA values to zero but this is not appropriate as it 
 includes the zero as significant.

 ANY SUGGESTIONS



 #SCRIPT STARTS
 for (i in 1:length(ALLRESULTS[,1])) {
 significance_count = 0

 if (ALLRESULTS[i,16] = 0.05 )  significance_count = significance_count +1 
 else significance_count = significance_count
 if (ALLRESULTS[i,17] = 0.05 )  significance_count = significance_count +1 
 else significance_count = significance_count
 if (ALLRESULTS[i,18] = 0.05 )  significance_count = significance_count +1 
 else significance_count = significance_count
 if (ALLRESULTS[i,19] = 0.05 )  significance_count = significance_count +1 
 else significance_count = significance_count
 if (ALLRESULTS[i,20] = 0.05 )  significance_count = significance_count +1 
 else significance_count = significance_count
 if (ALLRESULTS[i,21] = 0.05 )  significance_count = significance_count +1 
 else significance_count = significance_count
 if (ALLRESULTS[i,22] = 0.05 )  significance_count = significance_count +1 
 else significance_count = significance_count

 ALLRESULTS[i,23] - significance_count}




 __
 R-help@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.


__
R-help@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.


Re: [R] seq(...) strange logical value

2009-06-08 Thread Linlin Yan
How about this:

 %==% - function(x, y) {
if (length(x)  1) {
  sapply(x, function(z) isTRUE(all.equal(z, y)));
} else {
  sapply(y, function(z) isTRUE(all.equal(z, x)));
}
 }
 seq(0, 1, by=0.1) %==% 0.1
 [1] FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 seq(0, 1, by=0.1) %==% 0.2
 [1] FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 seq(0, 1, by=0.1) %==% 0.3
 [1] FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 seq(0, 1, by=0.1) %==% 0.4
 [1] FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
 0.3 %==% seq(0, 1, by=0.1)
 [1] FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE


On Mon, Jun 8, 2009 at 4:45 PM, Grześgregori...@gmail.com wrote:

 Do you heve any idea why I get after this instruction everywhere false?
 seq (0, 1, by=0.1) == 0.3
  [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE

 But after different step it's ok:
 seq(0, 1, by=0.1) == 0.4
  [1] FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE

 --
 View this message in context: 
 http://www.nabble.com/seq%28...%29-strange-logical-value-tp23920374p23920374.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@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.


__
R-help@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.


Re: [R] how to sort data frame order by column?

2009-05-31 Thread Linlin Yan
e.g.
dat[ order(dat$a), ]

On Sun, May 31, 2009 at 2:34 PM, Угодай n/a ugo...@gmail.com wrote:
 I have a data frame, for exampe

 dat - data.frame(a=rnorm(5),b=rnorm(5),c=rnorm(5))
           a            b          c
 1 -0.1731141  0.002453991  0.1180976
 2  1.2142024 -0.413897606  0.7617472
 3 -0.9428484 -0.609312786  0.5132441
 4  0.1343336  0.178208961  0.7509650
 5 -0.1402286 -0.333476839 -0.4959459

 How to make dat2 from dat, where source data frame be ordered by any column?

        [[alternative HTML version deleted]]

 __
 R-help@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.


__
R-help@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.


Re: [R] How to set a filter during reading tables

2009-05-31 Thread Linlin Yan
I think you can use readLines(n=1) in loop to skip unwanted rows.

On Mon, Jun 1, 2009 at 12:56 AM,  g...@ucalgary.ca wrote:
 Thanks, Juliet.
 It works for filtering columns.
 I am also wondering if there is a way to filter rows.
 Thanks again.
 -james

 One can use colClasses to set which columns get read in. For the
 columns you don't
 want you can set those to NULL. For example,

 cc - c(NULL,rep(numeric,9))

 myData -
 read.table(myFile.txt,header=TRUE,colClasses=cc,nrow=numRows).


 On Wed, May 27, 2009 at 12:27 PM,  g...@ucalgary.ca wrote:
 We are reading big tables, such as,

 Chemicals -
 read.table('ftp://ftp.bls.gov/pub/time.series/wp/wp.data.7.Chemicals',header
 = TRUE, sep = '\t', as.is =T)

 I was wondering if it is possible to set a filter during loading so
 that
 we just load what we want not the whole table each time. Thanks,

 -james

 __
 R-help@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.





 __
 R-help@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.


__
R-help@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.


Re: [R] logical vector as a matrix

2009-05-29 Thread Linlin Yan
On Sat, May 30, 2009 at 2:48 AM, Grześ gregori...@gmail.com wrote:

 I have a vector like this:
 h - c(4, 6, NA, 12)
 and I create the secound logical vector like this:
 g - c(TRUE, TRUE, FALSE, TRUE)
Why don't you create vector g like this:
g - ! is.na(h)


 And my problem is that I would like to get  a new m vector as a rasult h
 and m but with missed NA value, for example:

 m = (4,6,12)
 Do you have any idea?
As what you tried to do:
m - h[g] # which got (4,6,12)
you can directly use:
m - h[ ! is.na(h) ]

__
R-help@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.


Re: [R] How to write a loop?

2009-05-27 Thread Linlin Yan
Why did you use different variable names rather than index of list/data.frame?

On Wed, May 27, 2009 at 6:34 PM, Maithili Shiva
maithili_sh...@yahoo.com wrote:
 Dear R helpers,

 Following is a R script I am using to run the Fast Fourier Transform. The csv 
 files has 10 columns with titles m1, m2, m3 .m10.

 When I use the following commands, I am getting the required results. The 
 probelm is if there are 100 columns, it is not wise to define 100 commands as 
 fk - ONS$mk and so on. Thus, I need some guidance to write the loop for the 
 STEP A and STEP B.

 Thanking in advance

 Regards

 Maithili



 My R Script

 ---

 ONS - read.csv(fast fourier transform.csv, header = TRUE)

   # STEP A

   f1 - ONS$m1

   f2 - ONS$m2

   f3 - ONS$m3

   f4 - ONS$m4

   f5 - ONS$m5

   f6 - ONS$m6

   f7 - ONS$m7

   f8 - ONS$m8

   f9 - ONS$m9

   f10 - ONS$m10

 #


   # STEP B

   g1 - fft(f1)

   g2 - fft(f2)

   g3 - fft(f3)

   g4 - fft(f4)

   g5 - fft(f5)

   g6 - fft(f6)

   g7 - fft(f7)

   g8 - fft(f8)

   g9 - fft(f9)

   g10 - fft(f10)


 #

   h - g1*g2*g3*g4*g5*g6*g7*g8*g9*g10

   j - fft((h), inverse = TRUE)/length(h)


 #




      Cricket on your mind? Visit the ultimate cricket website. Enter 
 http://beta.cricket.yahoo.com
        [[alternative HTML version deleted]]


 __
 R-help@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.



__
R-help@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.


Re: [R] How to exclude a column by name?

2009-05-27 Thread Linlin Yan
Hope this helps:

 df - data.frame(matrix(1:10,2))
 df
  X1 X2 X3 X4 X5
1  1  3  5  7  9
2  2  4  6  8 10
 df[,-2]
  X1 X3 X4 X5
1  1  5  7  9
2  2  6  8 10
 df[,-which(names(df)==X2)]
  X1 X3 X4 X5
1  1  5  7  9
2  2  6  8 10


On Wed, May 27, 2009 at 6:37 PM, Zeljko Vrba zv...@ifi.uio.no wrote:
 Given an arbitrary data frame, it is easy to exclude a column given its index:
 df[,-2].  How to do the same thing given the column name?  A naive attempt
 df[,-name] did not work :)

__
R-help@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.


Re: [R] Sort matrix by column 1 ascending then by column 2 decending

2009-05-27 Thread Linlin Yan
It's a very interesting problem. I just wrote a function for it:

order.matrix - function(m, columnsDecreasing = c('1'=FALSE), rows = 1:nrow(m))
{
  if (length(columnsDecreasing)  0)
  {
col - as.integer(names(columnsDecreasing[1]));
values - sort(unique(m[rows, col]), decreasing=columnsDecreasing[1]);
unlist(sapply(values, function(x) order.matrix(m,
columnsDecreasing[-1], which((1:nrow(m) %in% rows)  (m[,
col]==x);
  }
  else
  {
rows;
  }
}

For instance:
 m - matrix( c(2, 1, 1, 3, .5, .3, .5, .2), 4)
 m
 [,1] [,2]
[1,]2  0.5
[2,]1  0.3
[3,]1  0.5
[4,]3  0.2
 m[order.matrix(m),]
 [,1] [,2]
[1,]1  0.3
[2,]1  0.5
[3,]2  0.5
[4,]3  0.2
 m[order.matrix(m, c(1=FALSE, 2=TRUE)),]
 [,1] [,2]
[1,]1  0.5
[2,]1  0.3
[3,]2  0.5
[4,]3  0.2

Any comment is welcome! ;)

On Wed, May 27, 2009 at 11:04 PM, Linlin Yan yanlinli...@gmail.com wrote:
 m - matrix( c(2, 1, 1, 3, .5, .3, .5, .2), 4)
 m
     [,1] [,2]
 [1,]    2  0.5
 [2,]    1  0.3
 [3,]    1  0.5
 [4,]    3  0.2
 m[unlist(sapply(sort(unique(m[,1])), function(x) 
 which(m[,1]==x)[order(m[(m[,1]==x),2], decreasing=TRUE)])),]
     [,1] [,2]
 [1,]    1  0.5
 [2,]    1  0.3
 [3,]    2  0.5
 [4,]    3  0.2

 On Wed, May 27, 2009 at 8:39 PM, Paul Geeleher paulgeele...@gmail.com wrote:
 I've got a matrix with 2 columns and n rows. I need to sort it first
 by the values in column 1 ascending. Then for values which are the
 same in column 1, sort by column 2 decending. For example:

 2 .5
 1 .3
 1 .5
 3 .2

 Goes to:

 1 .5
 1 .3
 2 .5
 3 .2

 This is easy to do in spreadsheet programs but I can't seem to work
 out how to do it in R and haven't been able to find a solution
 anywhere.


 Thanks!

 -Paul.

 --
 Paul Geeleher
 School of Mathematics, Statistics and Applied Mathematics
 National University of Ireland
 Galway
 Ireland

 __
 R-help@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.



__
R-help@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.


Re: [R] Help needed on R output

2009-05-26 Thread Linlin Yan
Did you mean this:

 write.table(t, eol=,\n, row.names=FALSE, col.names=FALSE)
,
01001001011011101100,
1001001011010101,
1101110100000011,
000100100101001001011001,
000101101101101001101001,

Try ?write.table to get the detail of the function please.

On Tue, May 26, 2009 at 9:33 PM, peng chen rogerchan2...@gmail.com wrote:
 Thanks.

 I am sorry that I did not clearly put my question.

 I need to output the array like
  t - c(
 + ,
 + 01001001011011101100,
 + 1001001011010101,
 + 1101110100000011,
 + 000100100101001001011001,
 + 000101101101101001101001)

 to a datafile(e.g., .txt file) where each line is for a binary number in
 this format:
 ,
 01001001011011101100,
 

 I was trying to use R-function write.table, however, I wasn't able to get
 the trailing comma for each line(although I can get the double quotation
 marks).

 Thanks.

__
R-help@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.


Re: [R] Help needed on R output

2009-05-25 Thread Linlin Yan
 t - c(
+ ,
+ 01001001011011101100,
+ 1001001011010101,
+ 1101110100000011,
+ 000100100101001001011001,
+ 000101101101101001101001)
 {
+ cat ('rom_array := (\n');
+ for (i in 1:length(t)) {
+   cat('', t[i], '',
+ ifelse(i == length(t), '', ',\n'), sep='')
+ };
+ cat(')\n');
+ }
rom_array := (
,
01001001011011101100,
1001001011010101,
1101110100000011,
000100100101001001011001,
000101101101101001101001)


On Tue, May 26, 2009 at 12:30 PM, peng chen rogerchan2...@gmail.com wrote:
 Hi, R experts:

 I am trying to generate data output in the following format:

 rom_array := (
 ,
 01001001011011101100,
 1001001011010101,
 1101110100000011,
 000100100101001001011001,
 000101101101101001101001)

 I have all the necessary data line, however, I am having trouble generating
 the double quotation marks along with the trailing comma for each line.

 Anyone can help?

 Thanks.

        [[alternative HTML version deleted]]

 __
 R-help@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.


__
R-help@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.


Re: [R] exists function on list objects gives always a FALSE

2009-05-19 Thread Linlin Yan
SmoothData$span is not an object which can be checked by exists(), but
part of an object which can be checked by is.null().

On Wed, May 20, 2009 at 12:07 AM, Žroutík zrou...@gmail.com wrote:
 Dear R-users,

 in a minimal example exists() gives FALSE on an object which obviously does
 exist. How can I check on that list object anyway else, please?

 SmoothData - list(exists=TRUE, span=0.001)
 SmoothData
 $exists
 [1] TRUE

 $span
 [1] 0.001

 exists(SmoothData)
 TRUE

 exists(SmoothData$span)
 FALSE

 exists(SmoothData[[2]])
 FALSE

 Thank you for any opinion regarding this topic.
 Zroutik

        [[alternative HTML version deleted]]

 __
 R-help@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.


__
R-help@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.


Re: [R] Concatenating two vectors into one

2009-05-18 Thread Linlin Yan
 z - paste(x, y, sep = '')
 z
[1] A1 B2 C3 D4 E5 F6

On Mon, May 18, 2009 at 7:09 PM, Henning Wildhagen hwildha...@gmx.de wrote:
 Dear users,

 a very simple question:

 Given two vectors x and y

 x-as.character(c(A,B,C,D,E,F))
 y-as.factor(c(1,2,3,4,5,6))

 i want to combine them into a single vector z as A1, B2, C3 and so on.

 z-x*y is not working, i tried several others function, but did not get to
 the solution.

 Thanks for your help,

 Henning


 --


        [[alternative HTML version deleted]]

 __
 R-help@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.


__
R-help@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.


Re: [R] Concatenating two vectors into one

2009-05-18 Thread Linlin Yan
It seems that c(x,y) is not correct:
 z-c(x,y)
 z
 [1] A B C D E F 1 2 3 4 5 6

On Mon, May 18, 2009 at 7:17 PM, Simon Pickett simon.pick...@bto.org wrote:
 z-c(x,y)

 cheers, Simon.


 - Original Message - From: Henning Wildhagen hwildha...@gmx.de
 To: r-help@r-project.org
 Sent: Monday, May 18, 2009 12:09 PM
 Subject: [R] Concatenating two vectors into one


 Dear users,

 a very simple question:

 Given two vectors x and y

 x-as.character(c(A,B,C,D,E,F))
 y-as.factor(c(1,2,3,4,5,6))

 i want to combine them into a single vector z as A1, B2, C3 and so on.

 z-x*y is not working, i tried several others function, but did not get to
 the solution.

 Thanks for your help,

 Henning


 --


 [[alternative HTML version deleted]]

 __
 R-help@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.


 __
 R-help@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.


__
R-help@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.


Re: [R] converting numeric to integer

2009-05-17 Thread Linlin Yan
On Sun, May 17, 2009 at 5:00 PM, Thomas Mang thomas.m...@fiwi.at wrote:
 Hi,

 Well, also not quite.
 Suppose x = 5.001 (in finite binary represenation). Then I want x ==
 5, but that is of course an integer which is now less than the original
 numeral.
Sorry for that I haven't got what your mean exactly about the finite
binary representation, because my English is not very good. How much
is the difference of x and 5 when result must be 5?

 Your code would turn it into 6;  moreover, your code would still work on
 numeric-values, so once it gets to the interger-conversion we are back at
 where the problem started, namely at the issue of finite floating-point
 representations, which might, or might not, yield the desired integer after
 the decimal digits have been truncated.

 BTW, do you know why sometimes replys do not appear in the newsgroups -
 mine to yours is not there, equally not your last response (althought the
 later might of course be the resuld because I made a mistak. in the first
 step)
The reason our last replys did not appear in the newsgroup is that you
replied to me only rather than to the maillist addres
r-h...@stat.math.ethz.ch.


 cheers and thanks,
 Thomas


 Linlin Yan wrote:

 I see. What you want is the integer with same sign as the original
 numeral, and whose absolute value is the least integer which is not
 less than absolute value of the original numeral. Am I right? I am
 afraid that there may not be any single function could work it out.
 But I could give the following expression:
 sign(x) * ceiling(abs(x)),
 which may be a little clearer.

 On Sun, May 17, 2009 at 2:02 PM, Thomas Mang thomas.m...@fiwi.at wrote:


 Hi,

 ceiling would do the wrong thing for negative values. If x = -4.999,
 the
 wanted result would be -5, but ceiling makes a -4 out of it.

 bye,
 Thomas

 Linlin Yan wrote:


 How about ceiling(x), which return the smallest integer not less than x?

 On Sun, May 17, 2009 at 2:49 AM, Thomas Mang thomas.m...@fiwi.at
 wrote:



 Hello,

 Suppose I have x, which is a variable of class numeric. The
 calculations
 performed to yield x imply that mathematically it should be an integer
 ,
 but
 due to round-off errors, it might not be (and so in either direction).
 The
 error is however small, so round(x) will yield the appropriate integer
 value. Moreover, this integer values is guaranteed to be representable
 by
 an
 'integer' class, that is -2^31  x  2^31, and logically it is an
 integer
 anyway. So I want to convert x from class 'numeric' to 'integer'. What
 is
 the most elegant, but always correct way, to achieve this conversion ?

 What comes to mind is of course something along:

 x = as.integer(round(x))

 I am, however, not sure if this always works, because I do not know if
 the
 round-function is guaranteed to return a numeric value which, in finite
 binary representation, is always = the underlying mathematical
 integer.
 If
 that is however guaranteed, that would of course be a simple + elegant
 one.

 An alternative I came up with is:

 x = as.integer(round(x) + ifelse(x = 0, 0.5, -0.5))
 Where I explicitly add a bit to ensure the finite binary representation
 must
 be = the underlying integer, and then truncate the decimal digits.
 IMO, this one is always guaranteed to work, at least within the
 numerical
 range of what integers are limited to anyway.


 What's your opinion on the issue ?
 Any other solution ?

 Thanks a lot in advance and cheers,
 Thomas

 __
 R-help@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.












__
R-help@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.


Re: [R] (no subject)

2009-05-16 Thread Linlin Yan
On Sat, May 16, 2009 at 12:05 PM, Debbie Zhang debbie0...@hotmail.com wrote:

 Dear R users,

 Does anyone know how to write a function involving derivative?

 i.e. I want to implementing Newton's method in R, so my function is something 
 like

 x- x-y/y'

 I am not sure how to write y' in my function. Can anyone help?



 In addition, if I want to implementing newton's method several times, what 
 code should I use?

 Currently, I use the following code.



 -1
Is this line x - 1?

 for (i in 1:20){
 + x-x-(x^3-2*x^2+3*x-5)/(3*x^2-4*x+3)}
 x
 [1] 1.843734

 However, when I typed in the following code, I would yield the same answer.
 -1
And is this line x - 1, too?

 for (i in 1:1){
 + x-x-(x^3-2*x^2+3*x-5)/(3*x^2-4*x+3)}
 x
 [1] 1.843734

Are you sure about this result?
What I got is like this:

 x - 1; for (i in 1:20) { x - x-(x^3-2*x^2+3*x-5)/(3*x^2-4*x+3); }; x
[1] 1.843734
 x - 1; for (i in 1:1) { x - x-(x^3-2*x^2+3*x-5)/(3*x^2-4*x+3); }; x
[1] 2.5

There are different!


 Can anyone suggest me what the problem is?

 Please help.
 Thanks so much.

 Debbie
 _
 View photos of singles in your area Click Here

 au%2Fsearch%2Fsearch%2Easpx%3Fexec%3Dgo%26tp%3Dq%26gc%3D2%26tr%3D1%26lage%3D18%26uage%3D55%26cl%3D14%26sl%3D0%26dist%3D50%26po%3D1%26do%3D2%26trackingid%3D1046138%26r2s%3D1_t=773166090_r=Hotmail_Endtext_m=EXT
        [[alternative HTML version deleted]]

 __
 R-help@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.


__
R-help@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.


Re: [R] converting numeric to integer

2009-05-16 Thread Linlin Yan
How about ceiling(x), which return the smallest integer not less than x?

On Sun, May 17, 2009 at 2:49 AM, Thomas Mang thomas.m...@fiwi.at wrote:
 Hello,

 Suppose I have x, which is a variable of class numeric. The calculations
 performed to yield x imply that mathematically it should be an integer , but
 due to round-off errors, it might not be (and so in either direction). The
 error is however small, so round(x) will yield the appropriate integer
 value. Moreover, this integer values is guaranteed to be representable by an
 'integer' class, that is -2^31  x  2^31, and logically it is an integer
 anyway. So I want to convert x from class 'numeric' to 'integer'. What is
 the most elegant, but always correct way, to achieve this conversion ?

 What comes to mind is of course something along:

 x = as.integer(round(x))

 I am, however, not sure if this always works, because I do not know if the
 round-function is guaranteed to return a numeric value which, in finite
 binary representation, is always = the underlying mathematical integer. If
 that is however guaranteed, that would of course be a simple + elegant one.

 An alternative I came up with is:

 x = as.integer(round(x) + ifelse(x = 0, 0.5, -0.5))
 Where I explicitly add a bit to ensure the finite binary representation must
 be = the underlying integer, and then truncate the decimal digits.
 IMO, this one is always guaranteed to work, at least within the numerical
 range of what integers are limited to anyway.


 What's your opinion on the issue ?
 Any other solution ?

 Thanks a lot in advance and cheers,
 Thomas

 __
 R-help@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.


__
R-help@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.


Re: [R] Duplicates and duplicated

2009-05-14 Thread Linlin Yan
On Thu, May 14, 2009 at 2:16 PM, christiaan pauw cjp...@gmail.com wrote:
 Hi everybody.
 I want to identify not only duplicate number but also the original number
 that has been duplicated.
 Example:
 x=c(1,2,3,4,4,5,6,7,8,9)
 y=duplicated(x)
 rbind(x,y)

 gives:
    [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 x    1    2    3    4    4    5    6    7    8     9
 y    0    0    0    0    1    0    0    0    0     0

 i.e. the second 4 [,5] is a duplicate.

 What I want is the first and second 4. i.e [,4] and [,5] to be TRUE

    [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 x    1    2    3    4    4    5    6    7    8     9
 y    0    0    0    1    1    0    0    0    0     0


How about

rbind(x, duplicated(x) | duplicated(x, fromLast=TRUE))
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
x123445678 9
 000110000 0

 I assume it can be done by sorting the vector and then checking is the next
 or the previous entry matches using
 identical() . I am just unsure on how to write such a loop the logic of
 which (I think) is as follows:

 sort x
 for every value of x check if the next value is identical and return TRUE
 (or 1) if it is and FALSE (or 0) if it is not
 AND
 check is the previous value is identical and return TRUE (or 1) if it is and
 FALSE (or 0) if it is not

 Im i thinking correct and can some help to write such a function

 regards
 Christiaan

        [[alternative HTML version deleted]]

 __
 R-help@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.


__
R-help@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.


Re: [R] Duplicates and duplicated

2009-05-14 Thread Linlin Yan
The operator %in% is very good! And that can be simpler like this:
x %in% x[duplicated(x)]
 [1] FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE

On Thu, May 14, 2009 at 4:43 PM, Andrej Blejec andrej.ble...@nib.si wrote:
 Try this

 x%in%x[which(y)]

 From your example

 x=c(1,2,3,4,4,5,6,7,8,9)
 y=duplicated(x)
 rbind(x,y)
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 x    1    2    3    4    4    5    6    7    8     9
 y    0    0    0    0    1    0    0    0    0     0
 which(y)
 [1] 5
 x[which(y)]
 [1] 4
 x%in%x[which(y)]
  [1] FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE

 Andrej

 --
 Andrej Blejec
 National Institute of Biology
 Vecna pot 111 POB 141
 SI-1000 Ljubljana
 SLOVENIA
 e-mail: andrej.ble...@nib.si
 URL: http://ablejec.nib.si
 tel: + 386 (0)59 232 789
 fax: + 386 1 241 29 80
 --
 Organizer of
 Applied Statistics 2009 conference
 http://conferences.nib.si/AS2009


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of christiaan pauw
 Sent: Thursday, May 14, 2009 8:17 AM
 To: r-help@r-project.org
 Subject: [R] Duplicates and duplicated

 Hi everybody.
 I want to identify not only duplicate number but also the original
 number
 that has been duplicated.
 Example:
 x=c(1,2,3,4,4,5,6,7,8,9)
 y=duplicated(x)
 rbind(x,y)

 gives:
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 x    1    2    3    4    4    5    6    7    8     9
 y    0    0    0    0    1    0    0    0    0     0

 i.e. the second 4 [,5] is a duplicate.

 What I want is the first and second 4. i.e [,4] and [,5] to be TRUE

     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 x    1    2    3    4    4    5    6    7    8     9
 y    0    0    0    1    1    0    0    0    0     0

 I assume it can be done by sorting the vector and then checking is the
 next
 or the previous entry matches using
 identical() . I am just unsure on how to write such a loop the logic
 of
 which (I think) is as follows:

 sort x
 for every value of x check if the next value is identical and return
 TRUE
 (or 1) if it is and FALSE (or 0) if it is not
 AND
 check is the previous value is identical and return TRUE (or 1) if it
 is and
 FALSE (or 0) if it is not

 Im i thinking correct and can some help to write such a function

 regards
 Christiaan

       [[alternative HTML version deleted]]

 __
 R-help@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.

 __
 R-help@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.


__
R-help@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.


Re: [R] Simulation

2009-05-14 Thread Linlin Yan
Since you got the most suitable way to get x, why can't you get the
variances in the same way? Just like:
  v = vector()
  for (i in 1:length(x)) v[i] = var(x[[i]])

BTW, it is much better to use lapply, like this:
  lapply(x, var)

On Thu, May 14, 2009 at 8:26 PM, Debbie Zhang debbie0...@hotmail.com wrote:

 Thanks for everyone.



 I think the approach below is most suitable for me, as a beginner.

 x=list()
  for(i in 1:n){
  x[[i]]=rnorm(i,0,1)
  }



 Now, I am trying to obtain the sample variance (S^2) of the 1000 samples that 
 I have generated before.

 I am wondering what command I should use in order to get the sample variance 
 for all the 1000 samples.



 What I am capable of doing now is just typing in

 var(z[[1]])

 var(z[[2]]).



 Thanks for help.



 Debbie


__
R-help@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.


Re: [R] Simulation

2009-05-13 Thread Linlin Yan
Does every 100 numbers in rnorm(100 * 1000, 0, 1) have the N(0,1) distribution?

On Wed, May 13, 2009 at 11:13 PM, Debbie Zhang debbie0...@hotmail.com wrote:


 Dear R users,

 Can anyone please tell me how to generate a large number of samples in R, 
 given certain distribution and size.

 For example, if I want to generate 1000 samples of size n=100, with a N(0,1) 
 distribution, how should I proceed?

 (Since I dont want to do rnorm(100,0,1) in R for 1000 times)



 Thanks for help



 Debbie

 _
 Looking to change your car this year? Find car news, reviews and more

 e%2Ecom%2Fcgi%2Dbin%2Fa%2Fci%5F450304%2Fet%5F2%2Fcg%5F801459%2Fpi%5F1004813%2Fai%5F859641_t=762955845_r=tig_OCT07_m=EXT
        [[alternative HTML version deleted]]

 __
 R-help@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.


__
R-help@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.