Displaying 20 results from an estimated 10000 matches similar to: "new syntax: bash-like pipe operator"
2011 Apr 03
2
converting "call" objects into character
Dear all,
I would like to log the calls to my functions. I am trying to do this using the function match.call():
fTest<-function(x)
{
theCall<-match.call()
print(theCall)
return(x)
}
> fTest(2)
fTest(x = 2)
[1] 2
I can see "theCall" printed into the console, but I don't manage to convert it into a character to write it into a log file
2013 Mar 12
2
ls() with different defaults: Solution;
Dear useRs,
Some time ago I queried the list as to an efficient way of building a function which acts as ls() but with a different default for all.names:
http://tolstoy.newcastle.edu.au/R/e6/help/09/03/7588.html
I have struck upon a solution which so far has performed admirably. In particular, it uses ls() and not its explicit source code, so only has a dependency on its name and the name of
2010 Nov 25
4
Cumsum with a max and min value
I have a vector of values -1, 0, 1, say
a <- c(0, 1, 0, 1, 1, -1, -1, -1, 0, -1, -1)
I want to create a vector of the cumulative sum of this, but I need to set a
maximum and minimum value for the cumsum, for example:
max_value <- 2
min_value <- -2
the expected result would be (0, 1, 1, 2, 2, 1, 0, -1, -1, -2, -2)
The only way I managed to do It, was
res <-
2010 Oct 12
5
aggregate with cumsum
Hello everybody,
Data is
myd <- data.frame(id1=rep(c("a","b","c"),each=3),id2=rep(1:3,3),val=rnorm(9))
I want to get a cumulative sum over each of id1. trying aggregate does not work
myd$pcum <- aggregate(myd[,c("val")],list(orig=myd$id1),cumsum)
Please suggest a solution. In real the dataframe is huge so looping with for and subsetting is not a
2005 Aug 17
2
About R variable references
Hello Group,
I could use an advice on how SEXP handles work. My aim is to implement a
system where I initially set a few global variables that are used for
communication between C and R code. Then I do some work with R code and
periodically call a function of my own that will update the system
state. Such a design is useful for many purposes (for GUIs to name one).
I am not entirely sure that R
2010 Nov 17
3
Parameterising apply To Compute Rolling Average of Columns in a matrix
I sent a post to find a clever way to compute a Rolling Average of columns
in a matrix and I was given the solution below which I am very pleased
with.
RollingAverage <- function(x, RollingObs) {
cx <- cumsum(x);
N <- length(x);
Temp <- (cx[RollingObs:N] - c(0, cx[1:(N-RollingObs)]))/RollingObs
Output <- array(NA, N)
Output[RollingObs:N] <- Temp;
Output
}
The only
2011 Mar 10
1
Moving window per group
Hi,
I have a data.frame of the following type:
F = data.frame(read.table(textConnection(" A B
1 1 4
2 1 3
3 1 1
4 1 4
5 1 2
6 1 2
7 1 2
8 2 1
9 2 1
10 2 1
11 2 1
12 3 2
13 3 4
14 3 1
15 3 1
16 3 1"),head=TRUE,stringsAsFactors=FALSE))
F
A B
1 1 4
2 1 3
3 1 1
4 1 4
5 1 2
6 1 2
7 1 2
8 2 1
9 2 1
10 2 1
11 2 1
12 3 2
13 3 4
14 3 1
15 3 1
16 3 1
2024 Jul 21
1
Using the pipe, |>, syntax with "names<-"
If you object to names(x)[2]<- ... then use replace:
z |> list(x = _) |> within(replace(names(x), 2, "foo")) |> _$x
On Sun, Jul 21, 2024 at 11:10?AM Bert Gunter <bgunter.4567 at gmail.com> wrote:
>
> hmmm...
> But note that you still used the nested assignment, names()[2] <-
> "foo", to circumvent R's pipe limitations, which is exactly
2024 Jul 21
1
Using the pipe, |>, syntax with "names<-"
hmmm...
But note that you still used the nested assignment, names()[2] <-
"foo", to circumvent R's pipe limitations, which is exactly what
Iris's solution avoids. So I think I was overawed by your cleverness
;-)
Best,
Bert
On Sun, Jul 21, 2024 at 8:01?AM Bert Gunter <bgunter.4567 at gmail.com> wrote:
>
> Wow!
> Yes, this is very clever -- way too clever for
2012 Feb 14
1
cumsum function to determine plankton phenology
Apologies for the empty email earlier!
I have species abundance data sampled at a weekly frequency or
sometimes monthly depending on the year.
The goal is to identify the dates in an annual cycle in which the
cumulative abundance of a species reaches some threshold.
Here's an example of the data for 1 species over an annual period:
"mc_pheno" is the object created from this data:
2024 Jul 21
1
Using the pipe, |>, syntax with "names<-"
This
- is non-destructive (does not change z)
- passes the renamed z onto further pipe legs
- does not use \(x)...
It works by boxing z, operating on the boxed version and then unboxing it.
z <- data.frame(a = 1:3, b = letters[1:3])
z |> list(x = _) |> within(names(x)[2] <- "foo") |> _$x
## a foo
## 1 1 a
## 2 2 b
## 3 3 c
On Sat, Jul 20, 2024 at
2024 Jul 21
3
Using the pipe, |>, syntax with "names<-"
Wow!
Yes, this is very clever -- way too clever for me -- and meets my
criteria for a solution.
I think it's also another piece of evidence of why piping in base R is
not suited for complex/nested assignments, as discussed in Deepayan's
response.
Maybe someone could offer a better Tidydata piping solution just for
completeness?
Best,
Bert
On Sun, Jul 21, 2024 at 7:48?AM Gabor
2024 Jul 20
2
Using the pipe, |>, syntax with "names<-"
This post is likely pretty useless; it is motivated by a recent post
from "Val" that was elegantly answered using Tidyverse constructs, but
I wondered how to do it using base R only. Along the way, I ran into
the following question to which I think my answer (below) is pretty
awful. I would be interested in more elegant base R approaches. So...
z <- data.frame(a = 1:3, b =
2008 Mar 31
1
How to give user a prompt before connecting thecall
Yes it is.
I'm remote at the moment so I can't send you the code but google for mobile remote receiver and you'll find what you are looking for.
Lots of people do it so they don't have calls to cell phones picked up by voicemail.
Cheers
dean
-----Original Message-----
From: Pete Kay <petedao at gmail.com>
Sent: Monday, March 31, 2008 2:27 PM
To: Asterisk Users Mailing
2011 Jul 06
3
identifying a 'run' in a vector
Hi,
How can I discern which elements in x (see below) are in 'order', but more
specifically.. only the 1st 'ordered run'?
I would like for it to return elements 1:8... there may be ordered values
after 1:8, but those are not of interest.
x <- c(1, 2, 3, 4, 5, 6, 7, 8, 20, 21, 22, 45)
Thanks for any suggestions.
--
View this message in context:
2012 Jul 16
2
Finding and manipulation clusters of numbers in a sequence of numbers
Hi,
I have the following sequence:
in <- c(0, 0, 0, 2, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 0, 2, 0, 0, 2)
>From this sequence I would like to get to the following sequence:
out <- c(0, 0, 0, 3, 3, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0,
0, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 0, 2, 0, 2, 0, 0, 2)
Basically,
2011 Feb 13
3
String manipulation
Please consider following string:
MyString <- "ABCFR34564IJVEOJC3434"
Here you see that, there are 4 groups in above string. 1st and 3rd groups
are for english letters and 2nd and 4th for numeric. Given a string, how can
I separate out those 4 groups?
Thanks for your time
[[alternative HTML version deleted]]
2011 Jan 06
1
[zoo] - Individual zoo or data frames from non-continuous zoo series
#Is there a way to break the below zoo object into non-NA data frames
algorithmically
#this is a small example of a much larger problem.
#It is really no even necessary to have the continuous chunks
#end up as zoo objects but it is important to have them end
#up with the index column.
#thanks for all of your help in advance, and
#if you need anything else please let me know
library(zoo)
ind.
2020 Aug 25
1
sum() vs cumsum() implicit type coercion
>>>>> Tomas Kalibera
>>>>> on Tue, 25 Aug 2020 09:29:05 +0200 writes:
> On 8/23/20 5:02 PM, Rory Winston wrote:
>> Hi
>>
>> I noticed a small inconsistency when using sum() vs cumsum()
>>
>> I have a char-based series
>>
>> > tryjpy$long
>>
>> [1]
2009 Jul 01
1
running count in data.frame
Hi,
I need to keep a running count of events that have happened in my
data.frame. I found a document called usingR that had an example of
doing this for random coin flips and I tried to modify it. It seems to
sort of work in the beginning, but then it stops and I don't
understand why. I'm trying to duplicate essentially the Excel
capability of =SUM($A$1:$A(Row number))
The example