I'm trying to manipulate a data frame in a loop, with R. This frame haves 100 observations with 3 variables.
#Lemmings in order
lemmings <- ds[order(ds$weights, ds$lifetimes),]
for(i in 100) {
#Amount of Sightings on that specific moment
s <- sum( lemmings[0:i,]$sightings )
l <- s / lemmings$lifetimes
w <- s / lemmings$weights
#Change values; this will show warnings!
lemmings$l[i] <- l
lemmings$w[i] <- w
print(l)
print(w)
}
print(lemmings)
When I try to manipulate the frame, to add $l and $w I got this warning:
Warning messages:
1: In lemmings$l[i] <- l :
number of items to replace is not a multiple of replacement length
2: In lemmings$w[i] <- w :
number of items to replace is not a multiple of replacement length
The data values $l, $w are still the same as before (lifetimes, weights), see one row:
sightings weights lifetimes l w
33.55230 0.579702 4 4.0000 0.579702
What can I do to remove the warnings messages, and to change the variables with my calculation?