我有一个名称数组,我想将这些名称用作数据框的列名,但出现了一些错误。我不确定该怎么做,但这就是我到目前为止所拥有的。
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
我必须将数组转换为某种类型的字符串或常量?