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
>>
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
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
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
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
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
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
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
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
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
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"),
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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)
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!
_
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,
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
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
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
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.
_
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.
__
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
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")
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
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
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
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
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,
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 <-
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
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
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.,
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
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
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
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
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",
"
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
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
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-
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
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
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) :
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
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
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
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
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
60 matches
Mail list logo