I am struggeling with the last exercise, I have tried it in many ways and I believe it should work now, but it is still not the required solution.
Could you please check it, whether it is a datacamp issue, or I still need to work on the code. Thank you in advance!
Please find my code below:
`library(nycflights13)
library(data.table)
library(ggplot2)
dt <- data.table(flights)
dt[,.N, by = dest]
Compute the average air time per destination and store the resulting data.table object in the airtime_by_dest variable. The column names should be dest and air_time
str(dt)
dt[, dest := factor(dest)]
str(dt)
airtime_by_dest <- dt[, list(air_time =mean(air_time, na.rm = TRUE)), by = dest][order(air_time)]
Running your code does not result in the preferred output, which should be something like
Hints:
reordering the factor levels is not exactly converting a character vector into a factor and then sorting the data.table -- see the examples from eg week 3
Dear Gergely Daroczi,
I am struggeling with the last exercise, I have tried it in many ways and I believe it should work now, but it is still not the required solution.
Could you please check it, whether it is a datacamp issue, or I still need to work on the code. Thank you in advance!
Please find my code below:
`library(nycflights13) library(data.table) library(ggplot2) dt <- data.table(flights) dt[,.N, by = dest]
Compute the average air time per destination and store the resulting data.table object in the airtime_by_dest variable. The column names should be dest and air_time
str(dt) dt[, dest := factor(dest)] str(dt) airtime_by_dest <- dt[, list(air_time =mean(air_time, na.rm = TRUE)), by = dest][order(air_time)]
str(airtime_by_dest) airtime_by_dest
Plot the bar plot
ggplot(airtime_by_dest, aes(dest)) + geom_bar()`