名前の配列があり、データフレームの列名にこれらの名前を使用したいのですが、エラーが発生します。これをどのように正確に行うかはわかりませんが、これは私がこれまでに持っていることです。
windspeeds = data.frame()
cities <- c("albuquerque_nm", "boston_ma", "charlotte_nc", "dallas_tx", "denver_co", "helena_mt", "louisville_ky", "pittsburgh_pa", "salt_lake_city_ut", "seattle_wa")
for(i in 1:10){
fastest <- read.delim(paste("http://www.itl.nist.gov/div898/winds/data/nondirectional/datasets/", cities[i], ".prn", sep=""), col.names=c("NULL", "fastest", "NULL", "NULL"), skip=4, header=F, sep="")$fastest
windspeeds$cities[i] = fastest
}
このエラーが発生します:
Error in `$<-.data.frame`(`*tmp*`, "cities", value = 59L) :
replacement has 1 rows, data has 0
In addition: Warning message:
In windspeeds$cities[i] = fastest :
number of items to replace is not a multiple of replacement length
配列をある種の文字列または定数に変換する必要がありますか?