R 将data.table转换合并到一行中

R 将data.table转换合并到一行中,r,data.table,R,Data.table,我已经编写了data.table数据转换代码: table_patterns <- table[, pattern := stringr::str_extract(LOG_MSG, "\\S+\\s+\\S+\\s+\\S+")] table_patterns <- table_patterns[, pattern := coalesce(stringr::str_extract(pattern, "^create new|regulate values

我已经编写了data.table数据转换代码:

table_patterns <- table[, pattern := stringr::str_extract(LOG_MSG, "\\S+\\s+\\S+\\s+\\S+")]
table_patterns <- table_patterns[, pattern := coalesce(stringr::str_extract(pattern, "^create new|regulate values"),pattern)]
table_patterns <- table_patterns[, system_type := case_when(class%in% c("class1", "class2") ~ "creation_class",class%in% c("class3","class4") ~ "uploading class")]
table_patterns <- table_patterns[, source := case_when(message%in% c("adapting new values within system|data wrangling and transformation in system") | class %in% c("class5", "class6") | pattern %in% c("user1 has uploaded new text") ~ "text_uploading",class %in% c("class7") ~ "alt_class",TRUE ~ "self_search"), by = .(class, pattern, system_type,source,message_type)][,
    

table\u patterns带有
数据。table
:=
修改到位。因此,不需要分配输出(
根据您的代码,您在这3行中创建了3列。@akrun是的。我想在一行中完成。如果可能的话,在第2行和第3行中,您的分组是相同的,但在最后一行中是不同的。因此,不清楚如何在一行中写入line@akrun我认为2和3的分组是没有必要的,只是最后一个matters@akrun我编辑了问题以及如何取消表的分组?告诉我please@french_fries使用
data.table
,它不会创建任何组属性。因此您不必这样做
library(data.table)
table[, pattern := stringr::str_extract(LOG_MSG, "\\S+\\s+\\S+\\s+\\S+")
      ][, pattern := coalesce(stringr::str_extract(pattern, 
         "^create new|regulate values"),pattern), by = .(class, pattern)
      ][, system_type := case_when(class%in% c("class1", "class2") ~
           "creation_class",
      class%in% c("class3","class4") ~ "uploading class"), by = .(class, pattern)
      ][, source := case_when(message %in% 
           c("adapting new values within system|data wrangling and transformation in system") | 
                class %in% c("class5", "class6") | 
                pattern %in% c("user1 has uploaded new text") ~
                   "text_uploading", 
                class %in% c("class7") ~ "alt_class",
         TRUE ~ "self_search"),
         by = .(class, pattern, system_type,source,message_type)][]