0

I have some basic house price data in london.

I have subset the data

Y2018 = subset(HP, Date == "2018" & PPDCategory.Type == "A")

I have then produced the mean, median, max and min values of transaction prices.

Year2018 = as.data.frame(tapply(Y2018$Price, Y2018$Ward, na.rm=TRUE, median))
Year2018$mean = (tapply(Y2018$Price, Y2018$Ward, na.rm=TRUE, mean))
Year2018$max = (tapply(Y2018$Price, Y2018$Ward, na.rm=TRUE, max))
Year2018$min = (tapply(Y2018$Price, Y2018$Ward, na.rm=TRUE, min))

This obviously now displays the first column as "tapply(Y2018$Price, Y2018$Ward, na.rm = TRUE, median)" - what is the correct way to make this column name be stored as "median".

tapply(Y2018$Price, Y2018$Ward, na.rm = TRUE, median)     mean     max    min
                                                                              375000 338600.0  460000 133000
Cann Hall Ward                                                                462000 451264.2  690000 205000
Cathall Ward                                                                  489000 482119.1  775000 175000
Chapel End Ward                                                               460000 451798.3  773500 162500
  • 1
    `Year2018 = as.data.frame(median = tapply(Y2018$Price, Y2018$Ward, na.rm=TRUE, median))` – ulfelder Mar 07 '19 at 10:57
  • For the code above, it produces an error: `as.data.frame(median = tapply(Y2018$Price, Y2018$Ward, na.rm = TRUE, : argument "x" is missing, with no default` – Jonathan West Mar 07 '19 at 14:35

1 Answers1

0

Sorry I misread, the answer to your question is here: Changing column names of a data frame

If I understand your question you can use tidyverse as follows

Year2018 %>%
  group_by(Ward) %>%
  mutate(mean = mean(price)) %>%
  mutate(max = max(price)) %>%
  mutate(min = min(price)) %>%
  ungroup() %>%
  unique()
Treizh
  • 322
  • 5
  • 12
  • Thank you, i'll try tidyverse. I am new to R following an online course called the Analytics Edge, where we have not used Tidyverse yet – Jonathan West Mar 07 '19 at 10:54