Re: [R] Problems using save to store NAMED R objects

2015-11-12 Thread Julio Sergio Santana
ote: > On 12/11/2015 6:41 PM, Julio Sergio Santana wrote: > >> I have to store (in a file) an R object that was created with is name as >> a string of characters, as follows: >> >> : nn <- "xxx" >> : assign(nn, 5) >> : xxx >>

[R] Problems using save to store NAMED R objects

2015-11-12 Thread Julio Sergio Santana
I have to store (in a file) an R object that was created with is name as a string of characters, as follows: : nn <- "xxx" : assign(nn, 5) : xxx [1] 5 I don't want to store the object nn but the object xxx. I tried the following two expressions but none of them worked: : save(ge

[R] Using split.screen with a definition matrix of the screens seems to be a mess. I don't understand!

2015-03-17 Thread Julio Sergio Santana
I have a particular need to divide the device space to draw different plots and texts, so I decided to use split.screen using a matrix to define the different space partitions. My code and explanation is as follows: # -- START OF R CODE dirGraf <- "TEST/" # A directory to put the resul

[R] legend with math (greek letters) symbols

2014-09-13 Thread Julio Sergio Santana
I need to add a legend with three entries that should contain a greek letter (lambda). I learnt that it is possible using the function expression. So I need to build the expressions from the lambdas vector, and I simply cannot do it. This is the uggly result I got: x <- 0:20 cc <- c("yellow

Re: [R] Curious behaviour of lapply and lists of functions

2014-01-15 Thread Julio Sergio Santana
Julio Sergio Santana gmail.com> writes: > ... > Producer <- function(f) function(x) 1/f(x) > Counsulting a previous post, I got to the solution, I just need to rewrite the function Producer forcing it to eavaluate its argument, as follows Producer <- function(f) {f

[R] Curious behaviour of lapply and lists of functions

2014-01-15 Thread Julio Sergio Santana
Let's say I define a simple list of functions, as follows lf <- list( function(x) x+5, function(x) 2*x ) Then I can take any individual function from the list and use it with any value, as it is shown: lf[[1]](3) [1] 8 lf[[2]](3) [1] 6 this gives me

Re: [R] R strange behaviour when working with fifos

2013-12-29 Thread Julio Sergio Santana
Julio Sergio Santana gmail.com> writes: > > I'm trying to establish a connection to a pair of fifos in R, one represents > the input stream of a process and the other one the output of the same > process. The problem is that R behaves very different when running the &g

[R] R strange behaviour when working with fifos

2013-12-27 Thread Julio Sergio Santana
I'm trying to establish a connection to a pair of fifos in R, one represents the input stream of a process and the other one the output of the same process. The problem is that R behaves very different when running the commands directly in the interpreter than when running via a script file. He

Re: [R] Using assign with mapply

2013-12-19 Thread Julio Sergio Santana
Greg Snow <538280 gmail.com> writes: > > The take home message that you should be learning from your struggles > is to "Not Use The 'assign' Function!" and "Do Not Use Global > Variables Like This". > > R has lists (and environments) that make working with objects that are > associated with eac

Re: [R] Using assign with mapply

2013-12-16 Thread Julio Sergio Santana
Julio Sergio Santana gmail.com> writes: > > I have a data frame whose first colum contains the names of the variables > and whose second colum contains the values to assign to them: > >: kkk <- data.frame(vars=c("var1", "var2", "var

Re: [R] Using assign with mapply

2013-12-10 Thread Julio Sergio Santana
David Winsemius comcast.net> writes: > So what happens if you try this: > > mapply(assign, kkk$vars, kkk$vals, MoreArgs = list(envir = .GlobalEnv) > Yes, it works in certain situations, as well as the equivalent code: kkk <- data.frame(vars=c("var1", "var2", "var3"),

[R] Using assign with mapply

2013-12-06 Thread Julio Sergio Santana
I have a data frame whose first colum contains the names of the variables and whose second colum contains the values to assign to them: : kkk <- data.frame(vars=c("var1", "var2", "var3"), vals=c(10, 20, 30), stringsAsFactors=F) If I do : assign(kkk$vars[1], kkk$vals

[R] Countour for netCDF-like meshes

2013-10-28 Thread Julio Sergio Santana
Hi, A model gives me as output a netCDF file which I read with ncdf package. The output consists of three similar matrices: one contains the variable value, and the other two, the longitude and latitude coordinates. I need to do a contour graph with such information, however, the R contour funct

[R] Transforming boolean subsetting into index subsetting

2013-06-28 Thread Julio Sergio
One of the techniques to subset, a vector for instance, is the following: V <- c(18, 8, 5, 41, 8, 7) V ## [1] 18 8 5 41 8 7 ( I <- abs(V - 9) <= 3 ) ## [1] FALSE TRUE FALSE FALSE TRUE TRUE V[I] ## [1] 8 8 7 However, sometimes we are interested in the indexes of the elements w

Re: [R] Trying to build up functions with its names by means of lapply

2013-06-06 Thread Julio Sergio
Bert Gunter gene.com> writes: > Another equivalent way to do it? > > f2 <- function(c,nm = "gamma",...) > { > probFunc <- paste0(c,nm) > more <- list(...) > function(x)do.call(probFunc,c(x,more)) > } > > This avoids the explicit use of get() and force(), I believe, but are > there problem

Re: [R] Trying to build up functions with its names by means of lapply

2013-06-05 Thread Julio Sergio
William Dunlap tibco.com> writes: > f1 <- function (c, nm = "gamma", ...) > { > probFunc <- getFunction(paste0(c, nm)) > force(list(...)) > function(x) probFunc(x, ...) > } > > Bill Dunlap > Spotfire, TIBCO Software > wdunlap tibco.com > Thanks a lot William!, this really enhances m

Re: [R] Trying to build up functions with its names by means of lapply

2013-06-05 Thread Julio Sergio
Bert Gunter gene.com> writes: > > faux <- function(c, nm = "gamma",...){ > f <- get(paste0(c,nm)) > function(x)f(x,...) > } > > This could be called with: > > > xgam <- lapply(c("p","d"), faux, shape=k, scale=theta) > > xgam[[1]](1000) > [1] 0.8710477 > > xgam[[2]](1000) > [1] 0

Re: [R] Trying to build up functions with its names by means of lapply

2013-06-05 Thread Julio Sergio
Rui Barradas sapo.pt> writes: > My solution works but it is incorrect. We should force the argument 'c', > > faux <- function(c) { > force(c) > function (x) get(paste0(c,"gamma"))(x,k,scale=theta) > } Thanks a lot, Rul. I think I have to learn a bit more about lazy evaluation of a

[R] Trying to build up functions with its names by means of lapply

2013-06-04 Thread Julio Sergio
I want to generate specific gamma distribution functions, given fixed parameters. This is I have k, and theta, say k <- 32.2549 # shape theta <- 26.32809 # scale # I have an auxiliary function that produces funcions according to # a given character (this is to have either d

Re: [R] I don't understand the 'order' function

2013-04-16 Thread Julio Sergio
William Dunlap tibco.com> writes: > > I think Duncan said that order and rank were inverses (if there are no ties). order() has > period 2 so order(order(x)) is also rank(x) if there are no ties. E.g., > Thanks William! This is very interesting. So, applying order two times I can have a ra

Re: [R] I don't understand the 'order' function

2013-04-16 Thread Julio Sergio
Julio Sergio gmail.com> writes: > > I thought I've understood the 'order' function, using simple examples like: Thanks to you all!... As Sarah said, what was damaged was my understanding ( ;-) )... and as Duncan said, I was confusing 'order' with 'ran

[R] I don't understand the 'order' function

2013-04-16 Thread Julio Sergio
I thought I've understood the 'order' function, using simple examples like: order(c(5,4,-2)) [1] 3 2 1 However, I arrived to the following example: order(c(2465, 2255, 2085, 1545, 1335, 1210, 920, 210, 210, 505, 1045)) [1] 8 9 10 7 11 6 5 4 3 2 1 and I was completely perpl

Re: [R] A strange behaviour in the graphical function

2013-04-12 Thread Julio Sergio
Jeff Newmiller dcn.davis.ca.us> writes: > > > system.time( miBeta( seq( 370, 430, length.out=1e5 ) ) ) > user system elapsed >1.300 0.024 1.476 > > system.time( miBetav( seq( 370, 430, length.out=1e5 ) ) ) > user system elapsed This is very interesting, Jeff. Of course, I appr

Re: [R] A strange behaviour in the graphical function "curve"

2013-04-12 Thread Julio Sergio
Berend Hasselman xs4all.nl> writes: > > Your function miBeta returns a scalar when the argument mu is a vector. > Use Vectorize to vectorize it. Like this > > VmiBeta <- Vectorize(miBeta,vectorize.args=c("mu")) > VmiBeta(c(420,440)) > > and draw the curve with this > > curve(VmiBeta,xli

Re: [R] A strange behaviour in the graphical function "curve"

2013-04-12 Thread Julio Sergio
Berend Hasselman xs4all.nl> writes: > > Yes. curve expects the function you give it to return a vector if the input argument is a vector. > This is clearly documented for the argument "expr" of curve. Thanks a lot, Berend! In fact, I didn't read carefully the documentation of "curve". Anyway

[R] A strange behaviour in the graphical function "curve"

2013-04-11 Thread Julio Sergio
I thought the curve function was a very flexible way to draw functions. So I could plot funtions like the following: # I created a function to produce functions, for instance: fp <- function(m,b) function(x) sin(x) + m*x + b # So I can produce a function like this ff <- fp(-0.08, 0.2)

Re: [R] Plotting several functions in the same display (again)

2013-04-04 Thread Julio Sergio
Duncan Murdoch gmail.com> writes: > The curve() function is trying to be clever, but it's not. You can > probably get what you want using curve(fi(380)(x), add=TRUE). It treats > the "x" argument specially. > > Duncan Murdoch > Thanks Duncan, Your solution worked perfectly! _

[R] Plotting several functions in the same display (again)

2013-04-04 Thread Julio Sergio
To superimpose two functions plots in the same page. The functions L0 and L1, as defined below, I use the following code: # An accumulative normal distribution function with # several parametres f0 <- function(mu, xm, ds, n) { 1 - pnorm((xm-mu)/(ds/sqrt(n))) } f1 <- function(mu,

Re: [R] ploting several functions on the same plot

2013-04-03 Thread Julio Sergio
Duncan Murdoch gmail.com> writes: > > curve(L1, add=TRUE) should handle it. > Thanks Duncan, Your solution worked great! However, I'm puzzled for a problem in the same line: When I passed a "function producer" to plot, again it works well; however it doesn't work in the same way when I try t

[R] ploting several functions on the same plot

2013-04-03 Thread Julio Sergio
I want to superimpose two functions plots in the same page. The functions L0 and L1, defined below f0 <- function(mu, xm, ds, n) { 1 - pnorm((xm-mu)/(ds/sqrt(n))) } f1 <- function(mu,n) f0(mu, 386.8, 48, n) L0 <- function(mu) f1(mu, 36) plot(L0,ylim=c(0,1),xlim=c(360,420)) L1

Re: [R] Coercing of types when raising a number to a series of powers

2013-02-07 Thread Julio Sergio
Julio Sergio gmail.com> writes: > > I'm trying to produce a series of powers of a number as follows: > > |> 0.05^0:5 I'm sorry for the question. The answer is simple: the result is due to operator precedence not to coercing: |> 0.05^(0:5) [1] 1.000e+0

[R] Coercing of types when raising a number to a series of powers

2013-02-07 Thread Julio Sergio
I'm trying to produce a series of powers of a number as follows: |> 0.05^0:5 [1] 1 2 3 4 5 This is not the result I expected. I guess some kind of coercion happened, since, |> class(0.05^0:5) [1] "integer" Could anyone explain me what is happening here? Thanks, -Sergio. _

Re: [R] Trying to use pipes in R

2012-09-12 Thread Julio Sergio
Thanks you all, With your recomendations I built my solution as follows: :> writeLines(c("uno dos tres", "cuatro cinco", "seis"), "tempfile.txt") :> o <- pipe("wc < tempfile.txt", open="r") :> readLines(o) :[1] " 3 6 31" best regards, --Sergio. __

Re: [R] Trying to use pipes in R

2012-09-12 Thread Julio Sergio Santana
t;uno dos tres", "cuatro cinco", "seis") > #get individual word count within quotes > res1<-unlist(lapply(strsplit(vec1, " "),length)) > res1 > #[1] 3 2 1 > > #get whole word count > length(unlist(strsplit(vec1, " "))) > #[1] 6

[R] Trying to use pipes in R

2012-09-12 Thread Julio Sergio Santana
Hi, I'm trying to use pipes in R. By now, I could launch the linux command "wc" (to count words from a text), but I don't know how to capture the results, say in a vector of chars... Here is the R code I'm trying: :> f <- pipe("wc", open="w") :> writeLines(c("uno dos tres", "cuatro cinco", "seis")

Re: [R] Some kind of inverse of "names"

2012-08-20 Thread Julio Sergio
Søren Højsgaard math.aau.dk> writes: > > Is this what you want?: > Yes, that is exactly what I wanted! Thanks, --Sergio. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R

[R] Some kind of inverse of "names"

2012-08-20 Thread Julio Sergio Santana
I wonder if there exists some kind of inverse of the "names" primitive in R. Let me explain what do I mean: If I create a list: -> li <- list(a=1, b=2, c=3, d=4) then I can have: -> names(li) [1] "a" "b" "c" "d" which is, I guess, some kind of vector, since -> typeof(names(li)) [1] "char

[R] Trying to build up a user interface with the R tcltk package

2012-08-07 Thread Julio Sergio Santana
I'm trying to build up a user inteface using the R tcltk component. Since the documentation for this R library is scarce and poor, I have decided to use only the .Tcl function to pass commands to the tcl interpreter. So I wrote my first very simple tcltk program, hoping to run it from inside R a

Re: [R] Reading several tables from stdin

2012-06-13 Thread Julio Sergio
Jeff Newmiller dcn.davis.CA.us> writes: > > problems. You also didn't supply the output of sessionInfo so we don't > even know your environment. I thought the output was provided, as I copied the output directly from my terminal. By the way the OS system is Ubuntu Linux 12.4 > If you are bou

Re: [R] Reading several tables from stdin

2012-06-13 Thread Julio Sergio
Julio Sergio gmail.com> writes: > > I'm trying to write a Rscript program capable of reading several tables from the > standard input. The problem is that the tables aren't in files because they > ... > Do you have any comments on this? > > Thanks, Well,

[R] Reading several tables from stdin

2012-06-13 Thread Julio Sergio
I'm trying to write a Rscript program capable of reading several tables from the standard input. The problem is that the tables aren't in files because they are coming from another process that is generating them. From the R-console the following works pretty well: |> f <- stdin() |> t <-

Re: [R] A kind of set operation in R

2012-04-05 Thread Julio Sergio
Berend Hasselman xs4all.nl> writes: > Try > > X %in% Y > > You could also have a look at match > > Berend > > Thanks Berend! --Sergio. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting

Re: [R] A kind of set operation in R

2012-04-05 Thread Julio Sergio
Richard M. Heiberger temple.edu> writes: > > At least two ways > > > (!is.na(match(X, Y))) > [1] FALSE TRUE TRUE FALSE TRUE TRUE > > X %in% Y > [1] FALSE TRUE TRUE FALSE TRUE TRUE Thanks Richard! --Sergio. __ R-help@r-project.org mailing li

[R] A kind of set operation in R

2012-04-05 Thread Julio Sergio
I have an ordered "set" of numbers, represented by a vector, say > X <- c(10:13, 17,18) > X [1] 10 11 12 13 17 18 then I have a "sub-set" of X, say > Y <- c(11,12,17,18) Is there a simple way in R to have a logical vector (parallel to X) indicating what elements of X are in Y, i.e.,

Re: [R] A function like sum but with functions other than '+'

2012-04-02 Thread Julio Sergio
Michael Sumner gmail.com> writes: > > Try ?Reduce > Thanks Michael! --Sergio. __ 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

[R] A function like sum but with functions other than '+'

2012-04-01 Thread Julio Sergio
Because I didn't find in R any functions similar to the function 'reduce' from Python, I'm writing a function "freduce" as follows: freduce <- function(f, vec, ValIni=NULL, StopIn=NULL) { # f: is any function that takes two arguments of the same type # vec: is a vector of n values accepted by

Re: [R] Trying to understand factors

2012-03-30 Thread Julio Sergio
David Winsemius comcast.net> writes: > > > I think you need to understand indexing more than you need to > understand factors. > > incomes [ which(statef == "act") ] > > If you want to understand how to programmatically access levels, then > you only need to follow the "See also" links o

Re: [R] Trying to understand factors

2012-03-30 Thread Julio Sergio
Sarah Goslee gmail.com> writes: > > Hi Julio, > > You can use a factor to index another object just as you'd use any other > index: > > incomes[statef == "act"] > [1] 46 43 > Is there something specific you're trying to accomplish? > > Sarah > Thanks Sarah! I'm just learning R. Thanks agai

[R] Trying to understand factors

2012-03-30 Thread Julio Sergio
I'm trying to figure out about factors, however the on-line documentation is rather sparse. I guess, factors are intended for grouping arrays members into categories, which R names "Levels". And so we have: * state <- c("tas", "sa", "qld", "nsw", "nsw", "nt", "wa", "wa", "

Re: [R] Handling functions as objects

2012-03-29 Thread Julio Sergio
David Winsemius comcast.net> writes: > > > There is also the `do.call` function to construct proper calls from a > character that matches the name of a function > > f1 = function(foo) { > do.call(foo, list(1,2)) >} > > f1("+") > [1] 3 > Thanks David, this information has bee

Re: [R] Handling functions as objects

2012-03-29 Thread Julio Sergio
Gabor Grothendieck gmail.com> writes: > > See ?match.fun > > There is also an enhanced version, match.funfn, in the gsubfn package. > Thanks Gabor! --Sergio. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEAS

Re: [R] Handling functions as objects

2012-03-29 Thread Julio Sergio
Duncan Murdoch gmail.com> writes: > You are seeing the effects of the evaluator and parser being helpful. > When you say > > foo(1,2) > > Thanks Duncan! --Sergio __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-

[R] Handling functions as objects

2012-03-29 Thread Julio Sergio
I learnt that functions can be handled as objects, the same way the variables are. So, the following is perfectly valid: > f = function(a, b) { +print(a) +print(b) + } > > f1 = function(foo) { +foo(1,2) + } > > f1(f) [1] 1 [1] 2 > I also know that operators are functions, so, I ca

Re: [R] Reading text files from other languages

2012-03-10 Thread Julio Sergio
Joshua Wiley gmail.com> writes: > > > Thanks Joshua! Best regards, --Sergio. __ 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 provid

[R] Reading text files from other languages

2012-03-10 Thread Julio Sergio
I'm trying to read a data file that contains characters from the Spanish language: > Station <- read.fwf("LosDatos.txt",widths=c(7,7,25,8,8,5),header=FALSE, + skip=3,n=separ[1]-4) Then the R interpreter issues the following message: Error en substring(x, first, last) :

Re: [R] Interacting with the Operating System

2012-03-09 Thread Julio Sergio
Sarah Goslee gmail.com> writes: > > No, that was your answer, not a request for clarification. > Type > ?system > at an R prompt and read the help file. > > Sarah > > On Fri, Mar 9, 2012 at 5:45 PM, Julio Sergio gmail.com> wrote: > > Sarah Goslee g

Re: [R] Interacting with the Operating System

2012-03-09 Thread Julio Sergio
Rolf Turner xtra.co.nz> writes: > > On 10/03/12 11:30, Julio Sergio wrote: > > Is there any way to issue operating system commands and geting back the results, > > in R? > > > > I mean, for instance, in Linux, to execute from R the 'ls' command a

Re: [R] Interacting with the Operating System

2012-03-09 Thread Julio Sergio
Sarah Goslee gmail.com> writes: > > ?system > > On Fri, Mar 9, 2012 at 5:30 PM, Julio Sergio gmail.com> wrote: > > Is there any way to issue operating system commands and geting back the results, > > in R? > > > > I mean, for instance, in Lin

[R] Interacting with the Operating System

2012-03-09 Thread Julio Sergio
Is there any way to issue operating system commands and geting back the results, in R? I mean, for instance, in Linux, to execute from R the 'ls' command and getting back a list of files in the current directory, or, equivalently, in Windows/DOS, the 'dir' command? I'm not interested in the

Re: [R] Intervals in function cut

2011-11-07 Thread Julio Sergio
Duncan Murdoch gmail.com> writes: ... Thanks Duncan! __ 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-c