That seems like sage advise :)
Thanks
Stefan
On 29 July 2016 at 22:06, Jeff Newmiller wrote:
> Having experienced some frustration myself when I first started with R
> many years ago, I can relate to your apparent frustration. However, if you
> would like to succeed in using R I strongly recom
Having experienced some frustration myself when I first started with R many
years ago, I can relate to your apparent frustration. However, if you would
like to succeed in using R I strongly recommend learning R and not trying to
write Haskell or Erlang or C or Fortran or any other language when
>> I still don't understand why you want Reduce to to lapply's
>> job. Reduce maps many to one and lapply maps many to
>> many.
Say you want to map a function over a subset of a vector or list? With the
generalised version of Reduce you map many-to-one, but the one can be a
'complex' structure.
Reduce (like lapply) apparently uses the [[ operator to
extract components from the list given to it. X[[i]] does
not attach names(X)[i] to its output (where would it put it?).
Hence your se
To help understand what these functions are doing try
putting print statements in your test functions:
> da
Jeremiah -
neat - that's one step closer, but one small thing I still don't understand:
> data <- list(one = c(1, 1), three = c(3), two = c(2, 2))
> r = Reduce(function(acc, item) { append(acc, setNames(length(item),
names(item))) }, data, list())
> str(r)
List of 3
$ : int 2
$ : int 1
$ : int
Basically using Reduce as an lapply in that example, but I think that was
caused by how people started talking about things in the first place =) But
the point is the accumulator can be anything as far as I can tell.
On Thu, Jul 28, 2016 at 12:14 PM, jeremiah rounds
wrote:
> Re:
> "What I'm tryi
Re:
"What I'm trying to
work out is how to have the accumulator in Reduce not be the same type as
the elements of the vector/list being reduced - ideally it could be an S3
instance, list, vector, or data frame."
Pretty sure that is not true. See code that follows. I would never solve
this task i
I am not as familiar with those other languages as I should be, but
in both examples aren't you using 'map' to call 'reduce' on each
component of a list? In R the basic mapping function is lapply.
> data <- list(one = c(1, 1), three = c(3), two = c(2, 2))
> rData <- lapply(X=data,
FUN=functio
Ulrik - many thanks for your reply.
I'm aware of many simple solutions as the one you suggest, both iterative
and functional style - but I'm trying to learn how to bend Reduce() for the
purpose of using it in more complex processing tasks. What I'm trying to
work out is how to have the accumulator
Hi Stefan,
in that case,lapply(data, length) should do the trick.
Best wishes,
Ulrik
On Thu, 28 Jul 2016 at 12:57 Stefan Kruger wrote:
> David - many thanks for your response.
>
> What I tried to do was to turn
>
> data <- list(one = c(1, 1), three = c(3), two = c(2, 2))
>
> into
>
> result <-
David - many thanks for your response.
What I tried to do was to turn
data <- list(one = c(1, 1), three = c(3), two = c(2, 2))
into
result <- list(one = 2, three = 1, two = 2)
that is creating a new list which has the same names as the first, but
where the values are the vector lengths.
I kno
> On Jul 27, 2016, at 8:20 AM, Stefan Kruger wrote:
>
> Hi -
>
> I'm new to R.
>
> In other functional languages I'm familiar with you can often seed a call
> to reduce() with a custom accumulator. Here's an example in Elixir:
>
> map = %{"one" => [1, 1], "three" => [3], "two" => [2, 2]}
> ma
If you have a simple list of vectors (call it lst), use
lengths = sapply(lst, length)
In general, you may want to look at functions lapply and sapply which
apply a function over a list, in this case the function length().
Peter
On Wed, Jul 27, 2016 at 8:20 AM, Stefan Kruger wrote:
> Hi -
>
> I
Hi -
I'm new to R.
In other functional languages I'm familiar with you can often seed a call
to reduce() with a custom accumulator. Here's an example in Elixir:
map = %{"one" => [1, 1], "three" => [3], "two" => [2, 2]}
map |> Enum.reduce(%{}, fn ({k,v}, acc) -> Map.update(acc, k,
Enum.count(v),
14 matches
Mail list logo