On 2012-07-07 03:19, fabiano wrote:
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

Have you taken a look at just what 'Hab' and 'habitat' contain?
It looks to me that 'habitat' is not a set of integers which it
would have to be to get habitat==i to be TRUE. I guess that
Hab[habitat==i, 1] is the empty set (hence 'length zero').

Peter Ehlers


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.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to