[R] replacement has length zero

fabiano chimbioputo at gmail.com
Sat Jul 7 12:19:25 CEST 2012


I have been working on the following code but keep getting an err message. My
current thinking is that the problem is on the indexing but do not know how
to fix it. Any help please?

ungulate <- read.csv("Ungulate.csv",row.names=1)
ungulate <-
as.matrix(ungulate);colnames(ungulate)<-NULL;rownames(ungulate)<-NULL
habitat <- read.csv("Ungulate_vegetation.csv")
habitat <- habitat[,3]
site.data <- read.csv("Ungulate_site.csv")
site <- site.data$SiteId
visit <- site.data$Visit
date <- site.data$Date
date <- matrix(date,nrow=20,ncol=7,byrow=TRUE)
S <- dim(ungulate)[1]
m <- 14	# number of augmented species
G <- read.csv("Ungulate_group.csv")
G <- G[,2]
g <- rep(NA,length=m)
G <- c(G,g) # combined list with actual and augmented data set so in this
case 6 + 14 
g <- length(table(G))
# habitat id
Hab <- cbind(seq(1,20),habitat) #habitat types for 20 sties run from 2 to 4

hab <- matrix(NA,nrow=2,ncol=7)    #creating placing values to be filled
with values generated by the following loop
for(i in 1:4){
	hab[i,] <- Hab[habitat==i,1]   }   # want to use this loop to substitute NA
by exact values as those found in the real data set which can be 2 to 4 but
keep getting an error message saying 

Error in hab[i, ] <- Hab[habitat == i, 1] : replacement has length zero

Any help. Thanks
Error in hab[i, ] <- Hab[habitat == i, 1] : replacement has length zero

--
View this message in context: http://r.789695.n4.nabble.com/replacement-has-length-zero-tp4635700.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list