我有这个df:
library(tidyverse)
library(magrittr)
df <- tibble(
Time = c('June 7', 'June 8', 'June 9', 'June 10', 'June 11', 'June 12', 'June 13', 'June 14', 'June 15', 'June 16', 'June 17', 'June 18', 'June 19', 'June 20', 'June 21', 'June 22', 'June 23', 'June 24', 'June 25', 'June 26', 'June 27', 'June 28'),
Measurements = c('105, 54, 79, 49, 31, 84, 55', '50, 105, 85, 72, 27, 43', '58, 26, 38', '67, 52, 92, 46', '73, 59, 62', '57, 24', '78, 96, 107', '76, 49, 40, 34, 44, 55', '18, 60, 39', '39, 55, 35', '86, 27, 91, 49, 23, 65, 32, 74', '32, 47, 57', '70, 56', '146, 39', '94, 39, 21, 72, 55', '48, 70, 10, 160', '126, 87, 107, 45, 55, 39', '33, 62, 38', '43, 63, 68, 21, 126, 87, 107', '56, 86, 64', '66, 55', '34, 44, 55, 72, 51, 42')
)
我想用逗号分隔Measurements
中的值,并计算每行的平均值(rowwise
)
我能够拆分并转换为数字:
df %>% lapply(str_split(.$Measurements, ', '), as.numeric)
但不知道如何从这里继续下去。任何帮助都是感激不尽的!
我可以在这里使用purrr::map
代替lapply
吗?
3条答案
按热度按时间dnph8jn41#
这是一种可行的方法:
第一个
mutmk8jj2#
一个黑客解决方案...
9bfwbjaz3#
我想你是在寻找这样的东西: