library(dplyr)
tib <- tibble(a = c(1,2,3))
按预期进行以下工作:
tib %>% mutate(b = a^2, c = sqrt(b))
# A tibble: 3 x 3
a b c
<dbl> <dbl> <dbl>
1 1 1 1
2 2 4 2
3 3 9 3
tib %>% mutate(b = a^2, c = sum(a))
# A tibble: 3 x 3
a b c
<dbl> <dbl> <dbl>
1 1 1 6
2 2 4 6
3 3 9 6
tib %>% mutate(b = a^2) %>% mutate(c = sum(b))
# A tibble: 3 x 3
a b c
<dbl> <dbl> <dbl>
1 1 1 14
2 2 4 14
3 3 9 14
以下内容不是:
tib %>% mutate(b = a^2, c = sum(b))
# A tibble: 3 x 3
a b c
<dbl> <dbl> <dbl>
1 1 1 1.482197e-323
2 2 4 1.482197e-323
3 3 9 1.482197e-323
我希望列c中的结果与上面相同,14到处都是。 关于我做错了什么的见解?