Skip to content

create a r list from dataframe using the first column as list names

2 messages · Rasmus Liland, Bert Gunter

#
On 2020-04-09 18:00 +0000, aiguo li wrote:
| That is awesome!  Thanks.

Dear AiGuo,

I thought: why make this overly 
complicated, when this is also 
possible:

  a <- matrix(LETTERS[1:16], nrow=4)
  X <- split(x=a[,-1], f=a[,1])
  lapply(X=X, FUN=as.factor)

Best,
Rasmus
#
"I thought: why make this overly complicated,..."

Indeed, though "complicated" is in the eyes of the beholder.
One wonders whether any of this is necessary, though: see ?apply , as in
apply(a, 1, whatever...)
to do things rowwise.

Cheers,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Fri, Apr 10, 2020 at 9:14 AM Rasmus Liland <jensrasmus at gmail.com> wrote: