回答編集履歴
3
test
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
```
|
1
|
+
```R
|
2
2
|
suppressMessages(library(tidyverse))
|
3
3
|
|
4
|
-
name <- c("Suzuki Yuta", "Suzuki Keiko", "Suzuki Koko", "Fujita Takashi", "Fujita Miki", "Fujita Tomoka
|
4
|
+
name <- c("Suzuki Yuta", "Suzuki Keiko", "Suzuki Koko", "Fujita Takashi", "Fujita Miki", "Fujita Tomoka", "Ooshima Kiyo", "Ooshima Ken")
|
5
5
|
Income_January <- c(43, 74, 80, 37, 20, 83, 64, 35)
|
6
6
|
Income_February <- c(55, 70, 82, 40, 22, 23, 60, 30)
|
7
7
|
df1 <- tibble(name, Income_January, Income_February)
|
8
8
|
|
9
9
|
df2 <- df1 %>%
|
10
|
-
group_by(
|
10
|
+
group_by(last_name = sub('^(.+?) .+$', '\\1', name)) %>%
|
11
11
|
summarize(
|
12
12
|
Total_Income_January = sum(Income_January),
|
13
13
|
Total_Income_February = sum(Income_February))
|
@@ -15,9 +15,10 @@
|
|
15
15
|
df2
|
16
16
|
|
17
17
|
# A tibble: 3 × 3
|
18
|
-
#
|
18
|
+
# last_name Total_Income_January Total_Income_February
|
19
|
-
# <chr>
|
19
|
+
# <chr> <dbl> <dbl>
|
20
|
-
# 1 Fujita
|
20
|
+
# 1 Fujita 140 85
|
21
|
-
# 2 Ooshima
|
21
|
+
# 2 Ooshima 99 90
|
22
|
-
# 3 Suzuki
|
22
|
+
# 3 Suzuki 197 207
|
23
23
|
```
|
24
|
+
|
2
test
CHANGED
@@ -6,11 +6,13 @@
|
|
6
6
|
Income_February <- c(55, 70, 82, 40, 22, 23, 60, 30)
|
7
7
|
df1 <- tibble(name, Income_January, Income_February)
|
8
8
|
|
9
|
-
df1 %>%
|
9
|
+
df2 <- df1 %>%
|
10
|
-
group_by(first_name = sub('^(
|
10
|
+
group_by(first_name = sub('^(.+?) .+$', '\\1', name)) %>%
|
11
11
|
summarize(
|
12
12
|
Total_Income_January = sum(Income_January),
|
13
13
|
Total_Income_February = sum(Income_February))
|
14
|
+
|
15
|
+
df2
|
14
16
|
|
15
17
|
# A tibble: 3 × 3
|
16
18
|
# first_name Total_Income_January Total_Income_February
|
1
test
CHANGED
@@ -2,18 +2,18 @@
|
|
2
2
|
suppressMessages(library(tidyverse))
|
3
3
|
|
4
4
|
name <- c("Suzuki Yuta", "Suzuki Keiko", "Suzuki Koko", "Fujita Takashi", "Fujita Miki", "Fujita Tomoka ", "Ooshima Kiyo", "Ooshima Ken")
|
5
|
-
Income_Janua
|
5
|
+
Income_January <- c(43, 74, 80, 37, 20, 83, 64, 35)
|
6
|
-
Income_Februa
|
6
|
+
Income_February <- c(55, 70, 82, 40, 22, 23, 60, 30)
|
7
|
-
df1 <- tibble(name, Income_Janua
|
7
|
+
df1 <- tibble(name, Income_January, Income_February)
|
8
8
|
|
9
9
|
df1 %>%
|
10
10
|
group_by(first_name = sub('^([^ ]+).+$', '\\1', name)) %>%
|
11
11
|
summarize(
|
12
|
-
Total_Income_January = sum(Income_Janua
|
12
|
+
Total_Income_January = sum(Income_January),
|
13
|
-
Total_Income_Februa
|
13
|
+
Total_Income_February = sum(Income_February))
|
14
14
|
|
15
15
|
# A tibble: 3 × 3
|
16
|
-
# first_name Total_Income_January Total_Income_Februa
|
16
|
+
# first_name Total_Income_January Total_Income_February
|
17
17
|
# <chr> <dbl> <dbl>
|
18
18
|
# 1 Fujita 140 85
|
19
19
|
# 2 Ooshima 99 90
|