gae*_*cia 5 r dataframe dplyr mutate
目前我必须使用add_column将新列直接插入到所需位置,或者使用mutate, 然后select使用新的所需列顺序。
mips.group <- str_extract(mips.manifest$PlateName, "[:alnum:]+_([[:alnum:]&&[^P]]+(_CL)?)?|(KORgex)")
mips.manifest %<>%
add_column(MIPSGroup=mips.group, .after="PlateName")
Run Code Online (Sandbox Code Playgroud)
是否可以直接告诉mutate在哪里添加新列,如果没有,是否有原因?
看看 mutate 的代码,看起来这并不容易,因为最终它会深入到 C 函数中:
\n\n> mutate\nfunction (.data, ...) \n{\n UseMethod("mutate")\n}\n<environment: namespace:dplyr>\n> methods(mutate)\n[1] mutate.data.frame* mutate.default* mutate.tbl_df* \nsee \'?methods\' for accessing help and source code\n> getAnywhere(mutate.tbl_df)\nA single object matching \xe2\x80\x98mutate.tbl_df\xe2\x80\x99 was found\nIt was found in the following places\n registered S3 method for mutate from namespace dplyr\n namespace:dplyr\nwith value\n\nfunction (.data, ...) \n{\n dots <- named_quos(...)\n mutate_impl(.data, dots)\n}\n<environment: namespace:dplyr>\n> mutate_impl\nError: object \'mutate_impl\' not found\n> getAnywhere(mutate_impl)\nA single object matching \xe2\x80\x98mutate_impl\xe2\x80\x99 was found\nIt was found in the following places\n namespace:dplyr\nwith value\n\nfunction (df, dots) \n{\n .Call(`_dplyr_mutate_impl`, df, dots)\n}\n<environment: namespace:dplyr>\nRun Code Online (Sandbox Code Playgroud)\n\n由于您已经有了可行的解决方案,因此修改是否会受到欢迎似乎值得怀疑。
\n