When running this code
projectile <- data.table()
projectile$angle<- c(15, 30, 45, 60, 75)
projectile$distance <- c(5.1, 8, 10, 8.5, 4.8)
ggplot() + geom_point( aes(projectile$angle, projectile$distance) ) # Works
ggplot(projectile) + geom_point( aes(angle,distance) ) # Does not work
I get this error:
Error in `$<-.data.frame`(x, name, value) :
replacement has 1 row, data has 0
Can anyone explain what this error means, why I have it and how to fix it, please?
UPDATE:
the same error occurs at earlier step if I use data.frame:
projectile <- data.frame()
projectile$angle<- c(15, 30, 45, 60, 75)
Error:
Error in `$<-.data.frame`(`*tmp*`, angle, value = c(15, 30, 45, 60, 75 :
replacement has 5 rows, data has 0
The reason why I dont create data.frame(angle=c(..), distance=c(..) right away is obviously that these values are NOT known until the user enters them later.
