Search notes:

R function: split

df <- data.frame(
  col_1 = c(   1 ,    2 ,    3 ,    4 ,    5 ,    6 ,    7 ,    8 ),
  col_2 = c('Foo', 'Foo', 'Bar', 'Foo', 'Baz', 'Baz', 'Foo', 'Bar')
)

sp <- split(df, df$col_2)

typeof(sp)
# [1] "list"

names(sp)
# [1] "Bar" "Baz" "Foo"

sp$Baz
#   col_1 col_2
# 5     5   Baz
# 6     6   Baz

sp2 <- split(df, c('A', 'A', 'A', 'B', 'A', 'B', 'B', 'A'))
sp2$B
#   col_1 col_2
# 4     4   Foo
# 6     6   Baz
# 7     7   Foo
Github repository about-r, path: /functions/split.R

See also

Index to (some) R functions

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758200745, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/R/functions/split(62): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78