Re: [R] help

2011-02-02 Thread Wacek Kusnierczyk
On 2/2/11 3:59 AM, Łukasz Ręcławowicz wrote: We don't need a loop! require(Rmpfr) factorial(mpfr(1:500,3800)) This is very good! I get an unexpected warning, though: Warning message: In if (mpfr.is.integer(x)) round(r) else r : the condition has length 1 and only the first element will

Re: [R] on gsub (simple, but not to me!) sintax

2009-11-16 Thread Wacek Kusnierczyk
Duncan Murdoch wrote: On 11/16/2009 8:21 AM, Ottorino-Luca Pantani wrote: Dear R users, my problem today deals with my ignorance on regular expressions. a matter I recently discovered. You were close. First, gsub by default doesn't need escapes before the parens. (There are lots of

Re: [R] Defining class as a member of another class

2009-06-28 Thread Wacek Kusnierczyk
Martin Morgan wrote: Gabor Grothendieck wrote: Try this: setClass(zoo) [1] zoo 'zoo' is I guess intended as an S3 class (from library zoo), so setOldClass('zoo') is appropriate. Otherwise, setClass(zoo) creates a new virtual class.

Re: [R] Defining class as a member of another class

2009-06-28 Thread Wacek Kusnierczyk
Peter Dalgaard wrote: Wacek Kusnierczyk wrote: Martin Morgan wrote: Gabor Grothendieck wrote: Try this: setClass(zoo) [1] zoo 'zoo' is I guess intended as an S3 class (from library zoo), so setOldClass('zoo') is appropriate. Otherwise, setClass(zoo) creates a new virtual

Re: [R] first value...

2009-06-23 Thread Wacek Kusnierczyk
Alfredo Alessandrini wrote: Hi, I've a vector like this: inc [1]NANANANANANANA [8]NANANANANANANA [15]NANANANANANA

Re: [R] [Rd] Floating point precision / guard digits? (PR#13771)

2009-06-21 Thread Wacek Kusnierczyk
Stavros Macrakis wrote [...] programming languages (including R). I don't know whether R's sum function uses this technique or some other (e.g. Kahan summation), but it does manage to give higher precision than summation with individual arithmetic operators: sum(c(2^63,1,-2^63)) = 1

Re: [R] How to change ONLY the first character of each variable name

2009-06-19 Thread Wacek Kusnierczyk
Henrique Dallazuanna wrote: Try this: gsub(^M{1}, MOLE, names(data)) {1} is inessential here. vQ On Thu, Jun 18, 2009 at 8:24 PM, Mark Na mtb...@gmail.com wrote: Dear R-helpers, I would like to adapt the following code names(data)-sub(M,MOLE,names(data)) which

Re: [R] where/what is i? for loop (black?) magic

2009-06-19 Thread Wacek Kusnierczyk
Duncan Murdoch wrote: Liaw, Andy wrote: A colleague and I were trying to understand all the possible things one can do with for loops in R, and found some surprises. I think we've done sufficient detective work to have a good guess as to what's going on underneath, but it would be nice to get

Re: [R] list of data.frames?

2009-06-17 Thread Wacek Kusnierczyk
Steve Jaffe wrote: I'm trying to build up a list of data.frames by appending one by one. If x,y,z are data.frames, I can do somelist - list(x, y, z) (or even somelist - list(x=x, y=y, z=z) to get names) But if I start with somelist - list(x,y) and now want to go from this to

Re: [R] tapply with cbinded x

2009-06-16 Thread Wacek Kusnierczyk
Stefan Uhmann wrote: Dear List, why does this not work? df - data.frame(var1 = c(3,2,1), var2 = c(6,5,4), var3 = c(9,8,7), fac = c('A', 'A', 'B')) tapply(cbind(df$var1, df$var2, df$var3), df$fac, mean) because length(cbind(df$var1, df$var2, df$var3)) # 9 length(df$fac)

Re: [R] tapply with cbinded x

2009-06-16 Thread Wacek Kusnierczyk
Stavros Macrakis wrote: On Tue, Jun 16, 2009 at 5:16 AM, Stefan Uhmann stefan.uhm...@googlemail.com wrote: why does this not work? df - data.frame(var1 = c(3,2,1), var2 = c(6,5,4), var3 = c(9,8,7), fac = c('A', 'A', 'B')) tapply(cbind(df$var1, df$var2, df$var3),

Re: [R] tapply with cbinded x

2009-06-16 Thread Wacek Kusnierczyk
Petr PIKAL wrote: Hi r-help-boun...@r-project.org napsal dne 16.06.2009 12:45:04: Stefan Uhmann wrote: Dear List, why does this not work? df - data.frame(var1 = c(3,2,1), var2 = c(6,5,4), var3 = c(9,8,7), fac = c('A', 'A', 'B')) tapply(cbind(df$var1, df$var2, df$var3),

Re: [R] Referencing data frames

2009-06-15 Thread Wacek Kusnierczyk
Payam Minoofar wrote: IGOR Pro has a built-in function that returns the name of an object as a string, and I was wondering if R has a similar facility. ?substitute ?deparse vQ __ R-help@r-project.org mailing list

Re: [R] Using ADF.Test

2009-06-10 Thread Wacek Kusnierczyk
Achim Zeileis wrote: [...] is.vector(as.vector(...)) is not necessarily TRUE. Consider x - cars[, 1, drop=FALSE] is.vector(x) is.vector(as.vector(x)) identical(x, as.vector(x)) interesting. i wonder why as.vector does not give, at the very least, a warning when the result of

Re: [R] using regular expressions to retrieve a digit-digit-dot structure from a string

2009-06-09 Thread Wacek Kusnierczyk
Gabor Grothendieck wrote: On Mon, Jun 8, 2009 at 7:18 PM, Wacek Kusnierczykwaclaw.marcin.kusnierc...@idi.ntnu.no wrote: Gabor Grothendieck wrote: Try this. See ?regex for more. x - 'This happened in the 21. century. (the dot behind 21 is' regexpr((?![0-9]+)[.], x, perl =

Re: [R] Regex question to find a string that contains 5-9 alpha-numeric characters, at least one of which is a number

2009-06-09 Thread Wacek Kusnierczyk
Marc Schwartz wrote: On Jun 8, 2009, at 5:27 PM, Barry Rowlingson wrote: On Mon, Jun 8, 2009 at 10:40 PM, Tan, Richardr...@panagora.com wrote: Hi, This is not exactly an R question but I am trying to use gsub to replace a string that contains 5-9 alpha-numeric characters, at least one of

Re: [R] Regex question to find a string that contains 5-9 alpha-numeric characters, at least one of which is a number

2009-06-09 Thread Wacek Kusnierczyk
Wacek Kusnierczyk wrote: Marc Schwartz wrote: On Jun 8, 2009, at 5:27 PM, Barry Rowlingson wrote: On Mon, Jun 8, 2009 at 10:40 PM, Tan, Richardr...@panagora.com wrote: Hi, This is not exactly an R question but I am trying to use gsub to replace a string that contains 5-9

Re: [R] using regular expressions to retrieve a digit-digit-dot structure from a string

2009-06-09 Thread Wacek Kusnierczyk
Gabor Grothendieck wrote: On Tue, Jun 9, 2009 at 3:04 AM, Wacek Kusnierczykwaclaw.marcin.kusnierc...@idi.ntnu.no wrote: Gabor Grothendieck wrote: On Mon, Jun 8, 2009 at 7:18 PM, Wacek Kusnierczykwaclaw.marcin.kusnierc...@idi.ntnu.no wrote: Gabor Grothendieck wrote:

Re: [R] using regular expressions to retrieve a digit-digit-dot structure from a string

2009-06-09 Thread Wacek Kusnierczyk
Marc Schwartz wrote: On Jun 9, 2009, at 6:44 AM, Mark Heckmann wrote: Hey all, Thanks for your help. Your answers solved the problem I posted and that is just when I noticed that I misspecified the problem ;) My problem is to separate a German texts by sentences. Unfortunately I haven't

Re: [R] Regex question to find a string that contains 5-9 alpha-numeric characters, at least one of which is a number

2009-06-09 Thread Wacek Kusnierczyk
Greg Snow wrote: Here is one way using a single pattern (so can be used in a substitution), it uses Perl's positive look ahead patters: test - c(SHRT,5HRT,M1TCH,M1TCH5,LONG3RS,NONUMBER,TOOLNGG,ooops.3) sub( '(?=[a-zA-Z]{0,8}[0-9])[a-zA-Z0-9]{5,9}', 'xxx', test, perl=TRUE)

Re: [R] Regex question to find a string that contains 5-9 alpha-numeric characters, at least one of which is a number

2009-06-09 Thread Wacek Kusnierczyk
Tan, Richard wrote: Sorry I did not give some examples in my previous posting to make my question clear. It's not exactly 1 digit, but at least one digit. Here are some examples: input = c(none='0foo f0oo foo0 foofoofoo0 0foofoofoo TOOL9NGG NONUMBER',all='foob0 fo0o0b 0foob

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

2009-06-08 Thread Wacek Kusnierczyk
Allan Engelhardt wrote: See http://wiki.r-project.org/rwiki/doku.php?id=misc:r_accuracy:decimal_numbers#sequences_of_decimal_numbers as usual, be careful about what is advertised in r docs and related texts. on the r_accuracy page, you'll read: For further information, see the digits

Re: [R] using regular expressions to retrieve a digit-digit-dot structure from a string

2009-06-08 Thread Wacek Kusnierczyk
Gabor Grothendieck wrote: Try this. See ?regex for more. x - 'This happened in the 21. century. (the dot behind 21 is' regexpr((?![0-9]+)[.], x, perl = TRUE) [1] 24 attr(,match.length) [1] 1 yes, but gregexpr('(?![0-9]+)[.]', 'a. 1. a1.', perl=TRUE) # 2 5 9 which,

Re: [R] S4: Initialization method called during setClass??

2009-06-05 Thread Wacek Kusnierczyk
Martin Morgan wrote: Hi Vitalie -- Vitalie S. wrote: Dear UseRs, A simple class inheritance example: setClass(test,representation(a=numeric)) setMethod(initialize,test, function(.Object,x,...){ print(Initialization!!!)

Re: [R] from 3 numeric variables to a string

2009-06-05 Thread Wacek Kusnierczyk
Marc Belisle wrote: Hi there, I have 3 numeric variables: day (e.g., 05), month (e.g., 06), year (e.g., 2009). I would like to create a (string) variable of the following form: month/day/year (e.g., 06/05/2009). I would be grateful to anyone who could point me toward a solution.

Re: [R] S4: Initialization method called during setClass??

2009-06-05 Thread Wacek Kusnierczyk
Martin Morgan wrote: [...] it sounds approximately ok that defining a subclass fails if its initalizer does not provide a value required by the initializer of the superclass. pardon me my ignorance, but here's an obvious question: what if i *do* want to extend a class that has an

Re: [R] Error:non-numeric argument in my function

2009-06-02 Thread Wacek Kusnierczyk
Stavros Macrakis wrote: I agree that it's inconsistent that 1:'2' -- 1:2 # this doesn't seem to be documented in ? seq 1+ '2' -- error 1+factor(2) -- NA (with a warning) 1 : factor(4) -- 1 (uses as.numeric/unclass of factor) ...i'd expect ...a successful

Re: [R] Error:non-numeric argument in my function

2009-06-01 Thread Wacek Kusnierczyk
i think the error message might be even better, but this would require '* to be even better. i know some will take it for lamenting: there is an ugly lack of consistency here: 1:2 # 1 2 1:2.5 # 1 2 (coercion double - integer) 1:'2' # 1 2 (corecion character - integer)

Re: [R] IP-Address

2009-05-31 Thread Wacek Kusnierczyk
edwin Sendjaja wrote: Hi VQ, Thank you. It works like charm. But I think Peter's code is faster. What is the difference? i think peter's code is more r-elegant, though less generic. here's a quick test, with not so surprising results. gsubfn is implemented in r, not c, and it is

Re: [R] IP-Address

2009-05-31 Thread Wacek Kusnierczyk
wow! :) vQ Henrik Bengtsson wrote: library(gsubfn) library(gtools) library(rbenchmark) n - 1 df - data.frame( a = rnorm(n), b = rnorm(n), c = rnorm(n), ip = replicate(n, paste(sample(255, 4), collapse='.'), simplify=TRUE) ) res - benchmark(columns=c('test', 'elapsed'),

Re: [R] String replacement in an expression

2009-05-29 Thread Wacek Kusnierczyk
William Dunlap wrote: Bill Dunlap TIBCO Software Inc - Spotfire Division wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Wacek Kusnierczyk Sent: Thursday, May 28, 2009 12:31 PM To: Caroline Bazzoli

Re: [R] custom sort?

2009-05-29 Thread Wacek Kusnierczyk
Steve Jaffe wrote: hmm, that is what I was afraid of. I considered that but thought to myself, surely there must be an easier way. I wonder why this feature isn't available. It's there in scripting languages, like perl, but also in hardcore languages like C++ where std::sort and sorted

Re: [R] custom sort?

2009-05-29 Thread Wacek Kusnierczyk
Duncan Murdoch wrote: On 28/05/2009 6:06 PM, Steve Jaffe wrote: hmm, that is what I was afraid of. I considered that but thought to myself, surely there must be an easier way. I wonder why this feature isn't available. It's there in scripting languages, like perl, but also in hardcore

Re: [R] custom sort?

2009-05-29 Thread Wacek Kusnierczyk
Stavros Macrakis wrote: I agree that it is surprising that R doesn't provide a sort function with a comparison function as argument. Perhaps that is partly because calling out to a function for each comparison is relatively expensive; R prefers vector operations. That said, many useful

Re: [R] IP-Address

2009-05-29 Thread Wacek Kusnierczyk
Peter Dalgaard wrote: Allan Engelhardt wrote: IP addresses are very (very!) difficult to parse and sort correctly because there are all sorts of supported formats. Try to use something like PostgreSQL instead: it is already implemented there. But if you are sure all your data is of the

Re: [R] How do I get removed from this mailing list?

2009-05-28 Thread Wacek Kusnierczyk
Peter Dalgaard wrote: Duncan Murdoch wrote: On 27/05/2009 8:25 PM, Andrey Lyalko wrote: How do I get removed from this mailing list? Like most lists nowadays, it gives the instructions in each message header: List-Unsubscribe: https://stat.ethz.ch/mailman/options/r-help,

Re: [R] How do I get removed from this mailing list?

2009-05-28 Thread Wacek Kusnierczyk
Gavin Simpson wrote: The View message source would be a more direct way of viewing the full email, not just the bits TBird shows you in the preview pane. I forget how it is named exactly and under which menu it is found as it has been quite a while since I used TBird. indeed; it's C-U,

Re: [R] split strings

2009-05-28 Thread Wacek Kusnierczyk
(diverted to r-devel, a source code patch attached) Wacek Kusnierczyk wrote: Allan Engelhardt wrote: Immaterial, yes, but it is always good to test :) and your solution *is* faster and it is even faster if you can assume byte strings: :) indeed; though if the speed is immaterial

Re: [R] String replacement in an expression

2009-05-28 Thread Wacek Kusnierczyk
Caroline Bazzoli wrote: Dear R-experts, I need to replace in an expression the character Cl by Cl+beta But in the following case: form-expression((Cl-(V *ka) ) +(V *Vm *exp(-(Clm/Vm) *t))) gsub(Cl,(Cl+beta),as.character(form)) We obtain: [1] ((Cl+beta) - (V * ka)) + (V * Vm *

Re: [R] split strings

2009-05-27 Thread Wacek Kusnierczyk
Allan Engelhardt wrote: Immaterial, yes, but it is always good to test :) and your solution *is* faster and it is even faster if you can assume byte strings: :) indeed; though if the speed is immaterial (and in this case it supposedly was), it's probably not worth risking fixed=TRUE removing

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

2009-05-27 Thread Wacek Kusnierczyk
Dieter Menne wrote: Peter Dalgaard P.Dalgaard at biostat.ku.dk writes: Or, BTW, you can use within() aq - within(airquality, rm(Day)) Please add this as an example to the docs of within. possibly with the slightly more generic unwanted - 'Day' aq -

Re: [R] split strings

2009-05-26 Thread Wacek Kusnierczyk
Monica Pisica wrote: Hi everybody, I have a vector of characters and i would like to extract certain parts. My vector is named metr_list: [1] F:/Naval_Live_Oaks/2005/data//BE.tif [2] F:/Naval_Live_Oaks/2005/data//CH.tif [3] F:/Naval_Live_Oaks/2005/data//CRR.tif [4]

Re: [R] split strings

2009-05-26 Thread Wacek Kusnierczyk
Monica Pisica wrote: Hi everybody, Thank you for the suggestions and especially the explanation Waclaw provided for his code. Maybe one day i will be able to wrap my head around this. Thanks again, you're welcome. note that if efficiency is an issue, you'd better have perl=TRUE

Re: [R] Creating a list by just using start and final component

2009-05-25 Thread Wacek Kusnierczyk
Romain Francois wrote: Hollix wrote: Hi there, say, I have 100 matrices (m1,m2,...,m100) which I want to combine in a list. The list, thus, shall contain the matrices as components. Is it necessary to mention all 100 matrices in the list() command? I would like to use just the first and

Re: [R] how to implement a circular buffer with R

2009-05-25 Thread Wacek Kusnierczyk
milton ruser wrote: Hi Maura, It is not elegant but may work. actual.string- 12345abcdefgh12345abcdefgh actual.string actual.string-paste(substr(actual.string, nchar(actual.string),nchar(actual.string)), substr(actual.string, 1,nchar(actual.string)-1), sep=) actual.string #in a

Re: [R] apply fn to many dataframes

2009-05-25 Thread Wacek Kusnierczyk
jim holtman wrote: You have to return a value from the function in the lapply and assign the result to another object: df - data.frame(a=1,b=2,c=3,d=4) a - list(df,df,df,df) # to change the name of the second, you have to change the name and then return # the dataframe as the

Re: [R] Functions returning functions

2009-05-20 Thread Wacek Kusnierczyk
Paulo Grahl wrote: Dear All: I have a question regarding the behavior of functions. Say I define a function that returns another function : A - function(parameters) { # calculations w/ parameters returning 'y' tmpf - function(x) { # function of 'y' } return(tmpf) } The

Re: [R] How to load data from Statistics Canada

2009-05-20 Thread Wacek Kusnierczyk
Peter Dalgaard wrote: g...@ucalgary.ca wrote: We would like to load data from Statistics Canada (http://www.statcan.gc.ca/) using R, for example, Employment and unemployment rates. It seems to me that the tables are displayed in HTML. I was wondering if you know how to load these tables.

Re: [R] Example for parsing XML file?

2009-05-20 Thread Wacek Kusnierczyk
Brigid Mooney wrote: Hi, I am trying to parse XML files and read them into R as a data frame, but have been unable to find examples which I could apply successfully. I'm afraid I don't know much about XML, which makes this all the more difficult. If someone could point me in the right

Re: [R] Generic 'diff'

2009-05-19 Thread Wacek Kusnierczyk
Stavros Macrakis wrote: On Mon, May 18, 2009 at 6:00 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: I understood what you were asking but R is an oo language so that's the model to use to do this sort of thing. I am not talking about creating a new class with an

Re: [R] Generic 'diff'

2009-05-19 Thread Wacek Kusnierczyk
Wacek Kusnierczyk wrote: Stavros Macrakis wrote: [...] I am not talking about creating a new class with an analogue to the subtraction function. I am talking about a function which applies another function to a sequence and its lagged version. Functional arguments are used all over

Re: [R] Generic 'diff'

2009-05-19 Thread Wacek Kusnierczyk
Wacek Kusnierczyk wrote: btw., the error message here is confusing: lag = 1:2 diff(1:10, lag=lag) # Error in diff.default(1:10, lag = lag) : # 'lag' and 'differences' must be integers = 1 is.integer(lag) # TRUE all(lag = 1) # TRUE what is meant

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

2009-05-19 Thread Wacek Kusnierczyk
Žroutík wrote: SmoothData - list(exists=TRUE, span=0.001) SmoothData $exists [1] TRUE $span [1] 0.001 exists(SmoothData) TRUE exists(SmoothData$span) FALSE 'SmoothData$span' = 'foo' exists(SmoothData$span) # TRUE exists(SmoothData[[2]])

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

2009-05-19 Thread Wacek Kusnierczyk
Linlin Yan wrote: SmoothData$span is not an object which can be checked by exists(), but part of an object which can be checked by is.null(). is.null is unhelpful here, in that lists can contain NULL as a named element, and retrieving a non-existent element returns NULL: foo =

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

2009-05-19 Thread Wacek Kusnierczyk
Stavros Macrakis wrote: You might think that you can check names(xxx) to see if the slot has been explicitly set, but it depends on *how* you have explicitly set the slot to NULL: xxx$hello - 3 xxx$hello - NULL names(xxx) character(0) # no names --

Re: [R] How do you save in R?

2009-05-18 Thread Wacek Kusnierczyk
ronggui wrote: I would second Dieter's point. me to, among others because: 2009/5/18 Dieter Menne dieter.me...@menne-biomed.de: Patrick Burns pburns at pburns.seanet.com writes: I disagree with Dieter's last point. Whether you use 'attach' or 'load' should depend on whether

Re: [R] Parsing configuration files

2009-05-18 Thread Wacek Kusnierczyk
Uwe Ligges wrote: Marie Sivertsen wrote: Dear list, Is there any functionality in R that would allow me to parse config files? Which kind of config files? R has read.dcf, for example. indeed, there are quite a number of more or less unambiguously specified configuration file formats.

Re: [R] sample variance from simulation

2009-05-18 Thread Wacek Kusnierczyk
Mike Lawrence wrote: why not simply vars=list() for (i in 1:1000) vars[[i]] = var(z[[i]]) ... or, much simpler, vars = sapply(z, var) vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the

Re: [R] displaying results

2009-05-15 Thread Wacek Kusnierczyk
Duncan Murdoch wrote: On 5/15/2009 8:33 AM, deanj2k wrote: Hi everyone, can anyone tell me how i can change how i display mean(age), i want it to say The mean age of patients within the sample is mean(age) I think you want something like this: cat(sprintf(The mean age of patients within

Re: [R] replace % with \%

2009-05-15 Thread Wacek Kusnierczyk
Marc Schwartz wrote: On May 15, 2009, at 9:46 AM, Liviu Andronic wrote: Dear all, I'm trying to gsub() % with \% with no obvious success. temp1 - c(mean, sd, 0%, 25%, 50%, 75%, 100%) temp1 [1] mean sd 0% 25% 50% 75% 100% gsub(%, \%, temp1, fixed=TRUE) [1] mean sd 0% 25%

Re: [R] Simulation

2009-05-15 Thread Wacek Kusnierczyk
Greg Snow wrote: Another possibility (maybe more readable, gives the option of a list, probably not faster): Replicate(1000, rexp(15,1) ) provided that simplify=FALSE: is(replicate(10, rexp(15, 1))) # matrix ... is(replicate(10, rexp(15, 1), simplify=FALSE)) # list ...

Re: [R] Simulation

2009-05-14 Thread Wacek Kusnierczyk
Barry Rowlingson wrote: On Wed, May 13, 2009 at 9:56 PM, Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no wrote: Barry Rowlingson wrote: n = 1000 benchmark(columns=c('test', 'elapsed'), order=NULL, 'for'={ l = list(); for (i in 1:n) l[[i]] = rnorm(i, 0, 1

Re: [R] Simulation

2009-05-14 Thread Wacek Kusnierczyk
Barry Rowlingson wrote: [...] Yes, you can probably vectorize this with lapply or something, but I prefer clarity over concision when dealing with beginners... but where's the preferred clarity in the for loop solution? Seriously? You think: lapply(1:n, rnorm, 0, 1) is

Re: [R] Simulation

2009-05-14 Thread Wacek Kusnierczyk
Dimitris Rizopoulos wrote: Wacek Kusnierczyk wrote: Barry Rowlingson wrote: On Wed, May 13, 2009 at 5:36 PM, Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no wrote: Barry Rowlingson wrote: Soln - for loop: z=list() for(i in 1:1000){z[[i]]=rnorm(100,0,1)} now inspect

Re: [R] Searching within a ch. string

2009-05-14 Thread Wacek Kusnierczyk
RON70 wrote: Thanks for these suggestions. However I have one more question. Is there any way to extract only numbers? For example I want to extract only 88 in my example. if you have just one integer number represented in a single string, here's one way go: strings = c('foo 1', '2

Re: [R] Simulation

2009-05-14 Thread Wacek Kusnierczyk
Peter Flom wrote: Seriously? You think: lapply(1:n, rnorm, 0, 1) is 'clearer' than: x=list() for(i in 1:n){ x[[i]]=rnorm(i,0,1) } for beginners? Firstly, using 'lapply' introduces a function (lapply) that doesn't have an intuitive name. Also, it takes a function as an

Re: [R] Simulation)

2009-05-14 Thread Wacek Kusnierczyk
Peter Flom wrote: As a beginner, I agree the for loop is much clearer to me. well, that's quite likely. especially given that typical courses in programming, afaik, include for looping but not necessarily functional stuff -- are you an r beginner, or a programming beginner?

Re: [R] Simulation

2009-05-14 Thread Wacek Kusnierczyk
Barry Rowlingson wrote: As a beginner, I agree the for loop is much clearer to me. [Warning: Contains mostly philosophy] maybe quasi ;) To me, the world and how I interact with it is procedural. When I want to break six eggs I do 'get six eggs, repeat break egg until all

Re: [R] Simulation

2009-05-14 Thread Wacek Kusnierczyk
Barry Rowlingson wrote: Computer scientists will write their beautiful manuscripts, but how many people who come to R because they want to do a t-test or fit a GLM will read them? That's the R-help audience now. don't forget that r seems to take, maybe undeserved, the pride of being a

Re: [R] specify the number of decimal numbers

2009-05-14 Thread Wacek Kusnierczyk
jim holtman wrote: Depending on what you want to do, use 'sprintf': x - 1.23456789 x [1] 1.234568 as.character(x) [1] 1.23456789 sprintf(%.1f %.3f %.5f, x,x,x) [1] 1.2 1.235 1.23457 ... but remember that sprintf introduces excel bugs into r

Re: [R] Simulation

2009-05-14 Thread Wacek Kusnierczyk
Stefan Grosse wrote: Debbie Zhang schrieb: 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

Re: [R] specify the number of decimal numbers

2009-05-14 Thread Wacek Kusnierczyk
(Ted Harding) wrote: On 14-May-09 12:27:40, Wacek Kusnierczyk wrote: ... but remember that sprintf introduces excel bugs into r (i.e., rounding is not done according to the IEC 60559 standard, see ?round): ns = c(0.05, 0.15) round(ns, 1) # 0.0 0.2 as.numeric(sprintf

Re: [R] specify the number of decimal numbers

2009-05-14 Thread Wacek Kusnierczyk
James W. MacDonald wrote: Wacek Kusnierczyk wrote: (Ted Harding) wrote: On 14-May-09 12:27:40, Wacek Kusnierczyk wrote: ... but remember that sprintf introduces excel bugs into r (i.e., rounding is not done according to the IEC 60559 standard, see ?round): ns = c(0.05, 0.15

Re: [R] specify the number of decimal numbers

2009-05-14 Thread Wacek Kusnierczyk
James W. MacDonald wrote: Wacek Kusnierczyk wrote: do they make pompous claims about their software and disregarding claims about others' as well? My mistake. I thought your concern was for the quality of the software (quality of course being defined by a certain committee of one

Re: [R] specify the number of decimal numbers

2009-05-14 Thread Wacek Kusnierczyk
(Ted Harding) wrote: This happens also when you use C's fprintf and sprintf (at any rate in my gcc): r's printing routines (e.g., print, sprintf, cat, anything else?) seem to rely on the underlying c sprintf, with no prior r-implemented rounding. hence they import into r whatever

Re: [R] Do you use R for data manipulation?

2009-05-13 Thread Wacek Kusnierczyk
Warren Young wrote: Farrel Buchinsky wrote: Is R an appropriate tool for data manipulation and data reshaping and data organizing? I think so but someone who recently joined our group thinks not. The new recruit believes that python or another language is a far better tool for developing

[R] where does the null come from?

2009-05-13 Thread Wacek Kusnierczyk
m = matrix(1:4, 2) apply(m, 1, cat, '\n') # 1 2 # 3 4 # NULL why the null? vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide

Re: [R] where does the null come from?

2009-05-13 Thread Wacek Kusnierczyk
Peter Dalgaard wrote: Wacek Kusnierczyk wrote: m = matrix(1:4, 2) apply(m, 1, cat, '\n') # 1 2 # 3 4 # NULL why the null? It comes from unlist()ing a list of NULLs, which in turn are the return values of cat(). yes; i'd think i'd get a list of nulls

Re: [R] Simulation

2009-05-13 Thread Wacek Kusnierczyk
Barry Rowlingson wrote: On Wed, May 13, 2009 at 4:26 PM, Gábor Csárdi csa...@rmki.kfki.hu wrote: On Wed, May 13, 2009 at 5: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

Re: [R] Simulation

2009-05-13 Thread Wacek Kusnierczyk
Barry Rowlingson wrote: On Wed, May 13, 2009 at 5:36 PM, Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no wrote: Barry Rowlingson wrote: Soln - for loop: z=list() for(i in 1:1000){z[[i]]=rnorm(100,0,1)} now inspect the individual bits: hist(z[[1]]) hist(z[[545

Re: [R] Read many .csv files into an R session automatically, without specifying filenames

2009-05-12 Thread Wacek Kusnierczyk
Romain Francois wrote: Hi, Something like this perhaps: files - dir( pattern = \\.csv$ ) for( x in files){ assign( sub( \\.csv$, , x ) , read.csv(x), envir = .GlobalEnv ) } or maybe csvs = Map(read.csv, dir(pattern='\\.csv$')) possibly with a correction of list item names

Re: [R] I'm offering $300 for someone who know R-programming to do the assignments for me.

2009-05-08 Thread Wacek Kusnierczyk
://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. -- --- Wacek Kusnierczyk, MD PhD

Re: [R] I'm offering $300 for someone who know R-programming to do the assignments for me.

2009-05-08 Thread Wacek Kusnierczyk
Simon Pickett wrote: I bet at least a few people offered their services! It might be an undercover sting operation to weed out the unethical amongst us :-) ... written by some of the r core developers? vQ __ R-help@r-project.org mailing list

Re: [R] Corrupt data frame construction - bug?

2009-04-30 Thread Wacek Kusnierczyk
Duncan Murdoch wrote: On 29/04/2009 6:41 PM, Steven McKinney wrote: foo - matrix(1:12, nrow = 3) bar - data.frame(foo) bar$NewCol - foo[foo[, 1] == 4, 4] bar X1 X2 X3 X4 NewCol 1 1 4 7 10 NA 2 2 5 8 11 NA 3 3 6 9 12 NA Warning message: In format.data.frame(x, digits =

Re: [R] Corrupt data frame construction - bug?

2009-04-30 Thread Wacek Kusnierczyk
Duncan Murdoch wrote: On 29/04/2009 9:21 PM, Steven McKinney wrote: Thanks Duncan, Comments and a proposed bug fix in-line below: Thanks; sorry for the misinformation about the $ method. maybe it's a good idea to change your strategy and avoid blaming users for faults that lie on the

Re: [R] use of input in system()

2009-04-30 Thread Wacek Kusnierczyk
Mike Miller wrote: On Fri, 24 Apr 2009, Duncan Murdoch wrote: On 4/24/2009 10:29 AM, Mike Miller wrote: First, it looks like there is bug in the documentation... According to the documentation for system(): http://stat.ethz.ch/R-manual/R-patched/library/base/html/system.html input

Re: [R] use of input in system()

2009-04-30 Thread Wacek Kusnierczyk
Wacek Kusnierczyk wrote and forgot to add references: it doesn't seem to be the usual way of explaining the matters. the bash reference manual [1, sec. 3.6.1] (see also man bash) says: [1] http://www.gnu.org/software/bash/manual/bashref.html in peters' expert shell scripting [2, ch. 9

Re: [R] Newbie R question PART2

2009-04-29 Thread Wacek Kusnierczyk
Wacek Kusnierczyk wrote: Dieter Menne wrote: R --vanilla which I like most because of the taste. once we talk about preferences, here's the version which i like most because of (a) least typing, (b) the non-pompous little r: ... and (c) superior performance

Re: [R] Newbie R question PART2

2009-04-29 Thread Wacek Kusnierczyk
Dieter Menne wrote: Tena Sakai tsakai at gallo.ucsf.edu writes: I learned 3 new tricks. (Not bad for a newbie?) $ R --silent --no-save barebone.R $ R --quiet --no-save barebone.R $ R --slave barebone.R And don't forget R --vanilla which I like most because of the

Re: [R] Newbie R question PART2

2009-04-29 Thread Wacek Kusnierczyk
Tena Sakai wrote: Hi, That's pretty impressive performance, but wait. Where does this little r come from? And how does it differ from its big brother? the little r comes from littler [1]. it doesn't claim to be larger than it is. [1] http://dirk.eddelbuettel.com/code/littler.html

Re: [R] send command to other program

2009-04-29 Thread Wacek Kusnierczyk
Jim Lemon wrote: thoeb wrote: Hello, does anybody know about how to send a command or a text line from R to another program? I have written a script in which several calculations are made and outputfiles (csv) are generated. Afterwards I open another program (Fortran) via shell.exec. This

Re: [R] Newbie R question

2009-04-28 Thread Wacek Kusnierczyk
Tena Sakai wrote: Hi, I am a newbie with R. My environment is linux and I have a file. I call it barebone.R, which has one line: cat ('Hello World!\n') I execute this file as: R --no-save barebone.R And it does what I expect. What I get is 20+/- lines of text, one of which is

Re: [R] Formatting numbers

2009-04-27 Thread Wacek Kusnierczyk
Mario dos Reis wrote: I've been trough the R documentation for about half an hour and it's not clear to me how to do this: I need to format to character a series of integers from 1 to 1000, and I like them to look like 0001 0002, 0059, 0123 and so on. Padded with zeroes to have four

Re: [R] Formatting numbers

2009-04-27 Thread Wacek Kusnierczyk
baptiste auguie wrote: sprintf(%04.f, 2) makes no sense to use the float specifier for ints here; besides, it's slower: x = 1:10^5 library(rbenchmark) benchmark(columns=c('test', 'elapsed'), replications=100, sprintf('%05d', x), sprintf('%05.f', x)) #

Re: [R] THE EQUIVALENT OF SQL INNER TABLE JOIN IN R

2009-04-26 Thread Wacek Kusnierczyk
Peter Dalgaard wrote: Nigel Birney wrote: Hello all, Apologize for the newbie question. What's the easiest way to do a SQL inner table join in R? Say I have a table containing column names A, B, C and another which has columns named C, D, E. I would like to do an inner table join on C and

Re: [R] rounding problem + sprintf

2009-04-24 Thread Wacek Kusnierczyk
Prof Brian Ripley wrote: I think your subject line should read 'Excel bug'. From the R help for round() Note that for rounding off a 5, the IEC 60559 standard is expected to be used, '_go to the even digit_'. In case you did not recognize it, IEC 60559 is an international

Re: [R] large factorials

2009-04-23 Thread Wacek Kusnierczyk
J Dougherty wrote: On Wednesday 22 April 2009 12:21:41 pm molinar wrote: I am working on a project that requires me to do very large factorial evaluations. On R the built in factorial function and the one I created both are not able to do factorials over 170. The first gives an error and

Re: [R] SAGE: was large factorials

2009-04-23 Thread Wacek Kusnierczyk
Albyn Jones wrote: On Wed, Apr 22, 2009 at 08:26:51PM -0700, Ben Bolker wrote: ??? octave is a Matlab clone, not a Mathematica clone (I would be interested in an open source Mathematica clone ...) ??? You might take a look at Sage. It is not a mathematica clone, but open

Re: [R] large factorials

2009-04-22 Thread Wacek Kusnierczyk
if you really really need to have it done from within r, you may want to use an external facility such as bc, the 'basic calculator' [1,2]. for example, use the (experimental!) r-bc: source('http://r-bc.googlecode.com/svn/trunk/R/bc.R') (you can also download the zipped package which will

Re: [R] explicit documentation

2009-04-21 Thread Wacek Kusnierczyk
Duncan Murdoch wrote: ronggui wrote: It is always unfair to complain about volunteer work, and what you should do is to make contributions. I only half agree with this: ... and i half agree with this (thus quarter agree with that). i think it's pretty fair to complain about unclear

  1   2   3   4   5   >