在dplyr::transmute中使用“粘贴”
“对于哪个数字在dplyr::transmute中使用“粘贴”,r,dplyr,R,Dplyr,“对于哪个数字x和y十进制数字系统中表示为6x12y的数字除以45?” 下面当然不是与我的doughter讨论的解决方案,而是尝试测试我在R中的技能。然而,最后一行并没有达到我想要的效果 library(tidyverse) library(stringi) replicate(2, 0:9, simplify = FALSE) %>% expand.grid() %>% as.tibble() %>% transmute(newcol=do.call(pa
x
和y
十进制数字系统中表示为6x12y
的数字除以45
?”
下面当然不是与我的doughter讨论的解决方案,而是尝试测试我在R中的技能。然而,最后一行并没有达到我想要的效果
library(tidyverse)
library(stringi)
replicate(2, 0:9, simplify = FALSE) %>%
expand.grid() %>%
as.tibble() %>%
transmute(newcol=do.call(paste0,list(6,Var1,12,Var2))) %>%
map_df(as.numeric) %>%
filter(newcol%%45==0) %>%
transmute(x_y=paste(stri_sub(newcol,c(2,5),c(2,5)),collapse = " "))
我用这个得到了想要的结果。但是我在上一篇文章中犯了什么错误
replicate(2, 0:9, simplify = FALSE) %>%
expand.grid() %>%
as.tibble() %>%
transmute(newcol=do.call(paste0,list(6,Var1,12,Var2))) %>%
map_df(as.numeric) %>%
filter(newcol%%45==0) %>%
transmute(x_y=map2_chr(stri_sub(newcol,2,2),stri_sub(newcol,5,5),paste))
您需要按顺序执行操作。因此,在管道中添加
rowwise()
library(tidyverse)
replicate(2, 0:9, simplify = FALSE) %>%
expand.grid() %>%
as.tibble() %>%
transmute(newcol=do.call(paste0,list(6,Var1,12,Var2))) %>%
map_df(as.numeric) %>%
filter(newcol%%45==0) %>%
rowwise() %>% # <--- Added the rowwise
transmute(x_y=paste(stri_sub(newcol,c(2,5),c(2,5)),collapse = " "))
库(tidyverse)
复制(2,0:9,simplify=FALSE)%>%
展开.grid()%>%
as.tible()%>%
transmute(newcol=do.call(paste0,list(6,Var1,12,Var2)))%>%
map_df(作为数值)%>%
过滤器(newcol%%45==0)%%>%
行()#
Source: local data frame [3 x 1]
Groups: <by row>
# A tibble: 3 x 1
x_y
<chr>
1 0 0
2 9 0
3 4 5