logo

Crowdly

Suppose you had the closing prices for four large technology stocks, and it was ...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

Suppose you had the closing prices for four large technology stocks, and it was given to you in this form:

stock_close

## # A tibble: 1,258 x 5

## Date AAPL AMZN FB GOOG

## <date> <dbl> <dbl> <dbl> <dbl>

## 1 2014-01-02 79.0 398. 54.7 553.

## 2 2014-01-03 77.3 396. 54.6 549.

## 3 2014-01-06 77.7 394. 57.2 555.

## 4 2014-01-07 77.1 398. 57.9 566.

## 5 2014-01-08 77.6 402. 58.2 567.

## 6 2014-01-09 76.6 401. 57.2 561.

## 7 2014-01-10 76.1 398. 57.9 561.

## 8 2014-01-13 76.5 391. 55.9 558.

## 9 2014-01-14 78.1 398. 57.7 571.

## 10 2014-01-15 79.6 396. 57.6 571.

## # i 1,248 more rows

Using the tidyr package, complete the code to convert this into a tidy format shown below:

library(tidyr)

stock_close |>

(cols = !Date, names_to = , values_to = )

## # A tibble: 5,032 x 3

## Date Symbol Close

## <date> <chr> <dbl>

## 1 2014-01-02 AAPL 79.0

## 2 2014-01-02 AMZN 398.

## 3 2014-01-02 FB 54.7

## 4 2014-01-02 GOOG 553.

## 5 2014-01-03 AAPL 77.3

## 6 2014-01-03 AMZN 396.

## 7 2014-01-03 FB 54.6

## 8 2014-01-03 GOOG 549.

## 9 2014-01-06 AAPL 77.7

## 10 2014-01-06 AMZN 394.

## # i 5,022 more rows

You’re writing an article on various diets for young chicks, and have computed this summary of the data:

ChickWeight |>

group_by(Time, Diet) |>

summarise(AverageWeight = mean(weight), .groups = "drop")

## # A tibble: 48 x 3

## Time Diet AverageWeight

## <dbl> <fct> <dbl>

## 1 0 1 41.4

## 2 0 2 40.7

## 3 0 3 40.8

## 4 0 4 41

## 5 2 1 47.2

## 6 2 2 49.4

## 7 2 3 50.4

## 8 2 4 51.8

## 9 4 1 56.5

## 10 4 2 59.8

## # i 38 more rows

Finish the code to convert this summary into a nice table for your report that looks like this:

ChickWeight |>

group_by(Time, Diet) |>

summarise(AverageWeight = mean(weight), .groups = "drop") |>

(names_from = , names_prefix = "Diet ", values_from = )

Time

Diet 1

Diet 2

Diet 3

Diet 4

0

41.4

40.7

40.8

41.0

2

47.2

49.4

50.4

51.8

4

56.5

59.8

62.2

64.5

6

66.8

75.4

77.9

83.9

8

79.7

91.7

98.4

105.6

10

93.1

108.5

117.1

126.0

12

108.5

131.3

144.4

151.4

14

123.4

141.9

164.5

161.8

16

144.6

164.7

197.4

182.0

18

158.9

187.7

233.1

202.9

20

170.4

205.6

258.9

233.9

21

177.8

214.7

270.3

238.6

More questions like this

Want instant access to all verified answers on learning.monash.edu?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!