0

Is there a way to ask R to use the split() function arbitrarily on any given data set by the last column without a column name or number? Something like [imaginary code land]:

d <- split(MY_DATA, ncol(MYDATA)) 

A sample data set might be something like:

pepsi  1
dr_pep 2
coke   1

Where our data set has no headers, by the last column would represent a desired grouping like the following:

dr_pep 2 --> group 2

pepsi  1  --> group 1
coke   1
Darkenor
  • 4,197
  • 8
  • 38
  • 65

1 Answers1

1
df <- read.table(text = 'pepsi  1
dr_pep 2
coke   1', header=F)

split(df, df[,ncol(df)])
Nimantha
  • 5,793
  • 5
  • 23
  • 56
1.618
  • 11,271
  • 1
  • 15
  • 32