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 b

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 differen

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.

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

2009-06-27 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. setClass("Work",representati

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] 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] 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 wrote: Dear R-helpers, I would like to adapt the following code names(data)<-sub("M","MOLE",names(data)) which changes any o

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 thi

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(

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 >> 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), df$fac, mean) >> >

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$

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 https://stat.ethz.ch/mailman

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

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 fo0o0

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

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 > Kusnierczyk wrote: > >> Gabor Grothendieck wrote: >> >>> On Mon, Jun 8, 2009 at 7:18 PM, Wacek >>> Kusnierczyk wrote: >>> >>> >>>> Gabor Grothe

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, Richard wrote: >>> >>>> Hi, >>>> >>>> This is not e

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, Richard 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 o

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 > Kusnierczyk wrote: > >> Gabor Grothendieck wrote: >> >>> Try this. See ?regex for more. >>> >>> >>> >>>> x <- 'This happened in the 21.

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)

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 digit

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] 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: > Hi Vitalie -- > > Vitalie S. wrote: > >> Dear UseRs, >> >> A simple class inheritance example: >> >> >>> setClass("test",representation(a="numeric")) >>> setMethod("initialize","test", >>> >> function(.Object,x,...){ >> print("Initializa

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

2009-06-02 Thread Wacek Kusnierczyk
Wacek Kusnierczyk wrote: > > interestingly, > > as.complex('0i') > # NA > but as.complex('0+0i') # 0+0i so that while just 0i is valid as a complex literal, '0i' is not valid as a string representing a complex. easy to lea

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

Re: [R] R constrict digits number after point precision?

2009-06-02 Thread Wacek Kusnierczyk
jim holtman wrote: > ?sprintf # for output > ?round > ... and sprintf(round(...)) for correct output vQ __ 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.

Re: [R] newbie help: simple operations in R

2009-06-02 Thread Wacek Kusnierczyk
Carletto Rossi wrote: > I'm sorry but i verify that Simon solution doesn't work. It makes only the > product between the corrispondent element of the columns (first with first, > second with seconds, etc,...) > These are the list of R commands: > > >> quattro <- read.csv('new_data.csv', header=T

Re: [R] creating list with 200 identical objects

2009-06-02 Thread Wacek Kusnierczyk
Rainer M Krug wrote: > Thanks a lot Wacek for this clear description of the problem - I was > not aware, that it is that complex. > I definitely did not consider the initialize() function in writing my code. > > But as I only want to allocate the space for the objects, it does not > matter here. Bu

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

2009-06-02 Thread Wacek Kusnierczyk
Stavros Macrakis wrote: > On Mon, Jun 1, 2009 at 11:33 AM, Wacek Kusnierczyk < > waclaw.marcin.kusnierc...@idi.ntnu.no> wrote: > > >> ... there is an ugly lack of consistency here:... >> >> > > I agree that it's inconsistent that >

Re: [R] R Solves Shakespeare Authorship Question

2009-06-02 Thread Wacek Kusnierczyk
Stavros Macrakis wrote: > I don't know why this paper is getting our attention here -- it is just an > undergraduate student term paper for a computer science course on statistics > and data mining. > "Those of you who track applications of R may be interested" vQ > -s > > On Mon

Re: [R] creating list with 200 identical objects

2009-06-01 Thread Wacek Kusnierczyk
Wacek Kusnierczyk wrote: > > consider: > > setClass('foo', >representation=representation(content='environment')) > setMethod('initialize', 'foo', function(.Object) { > .obj...@content = new.env() >

Re: [R] creating list with 200 identical objects

2009-06-01 Thread Wacek Kusnierczyk
Romain Francois wrote: > > rep( list( new("track") ), 5 ) > lapply( 1:5, function(x) new("track") ) > list( new("track") ) [ rep(1, 5 ) ] but note: these are not all equivalent. the second creates a list of five distinct objects, the first and last ones create a list of five times the same object

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

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 p

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 i

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] 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 >> "har

Re: [R] custom sort?

2009-05-28 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 c

Re: [R] String replacement in an expression

2009-05-28 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

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

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: >> > > :) &g

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'

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:

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

2009-05-27 Thread Wacek Kusnierczyk
Dieter Menne wrote: > Peter Dalgaard 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 <- within(airqua

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] 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=T

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

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.

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 j

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 ri

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 t

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

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 name

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

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

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(

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.

Re: [R] Generic 'diff'

2009-05-19 Thread Wacek Kusnierczyk
Stavros Macrakis wrote: > On Mon, May 18, 2009 at 6:00 PM, Gabor Grothendieck >> 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 analogue

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 rea

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 fil

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 : > >> Patrick Burns pburns.seanet.com> writes: >> >> >>> I disagree with Dieter's last point. >>> Whether you use 'attach' or 'load' >>> should depend on whether you want the >>> o

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)) # "

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

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 patient

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 stand

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

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 d

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)

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 ca

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 int

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

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"

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 beginne

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 n

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

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 >>> wrote: >>>> Barry Rowlingson wrote: >>>>> Soln - "for" loop: >>>>> >

Re: [R] Simulation

2009-05-13 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, rno

Re: [R] Simulation

2009-05-13 Thread Wacek Kusnierczyk
Barry Rowlingson wrote: > On Wed, May 13, 2009 at 9:56 PM, Wacek Kusnierczyk > wrote: > >> Barry Rowlingson wrote: >> > > >>n = 1000 >>benchmark(columns=c('test', 'elapsed'), order=NULL, >> 'for&#x

Re: [R] Simulation

2009-05-13 Thread Wacek Kusnierczyk
Barry Rowlingson wrote: > On Wed, May 13, 2009 at 5:36 PM, Wacek Kusnierczyk > wrote: >> Barry Rowlingson wrote: > >>> Soln - "for" loop: >>> >>> > z=list() >>> > for(i in 1:1000){z[[i]]=rnorm(100,0,1)} >>> >

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 wrote: > >> On Wed, May 13, 2009 at 5:13 PM, Debbie Zhang wrote: >> >>> Dear R users, >>> >>> Can anyone please tell me how to generate a large number of samples in R, >>> given certain distribution and size. >>> >>>

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

[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 http://www.R-project.org/posting-guide

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 d

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 i

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 http

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

2009-05-08 Thread Wacek Kusnierczyk
> > __ > 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] 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

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

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 th

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 >> 2 2 5 8 11 >> 3 3 6 9 12 >> Warning message: >> In format.

Re: [R] Mailinglist; get a copy of all own messages

2009-04-29 Thread Wacek Kusnierczyk
Sarah Goslee wrote: > It's gmail, not the mailing list. oops? it's a typical property of a mailing list manager that allows a subscriber to decide whether s/he want to receive copies of h{er,is} own posts. for r-help, you should be able to login at https://stat.ethz.ch/mailman/options/r-h

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 s

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] Newbie R question PART2

2009-04-29 Thread Wacek Kusnierczyk
Dieter Menne wrote: > Tena Sakai 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 mo

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 ty

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

  1   2   3   4   5   6   >