Hi, On Thursday, October 1, 2015, Thomas Chesney < thomas.ches...@nottingham.ac.uk> wrote:
> How can I manipulate values of only certain entries in a vector, based on > what the existing values are? > > So for instance if I want to add one to each of the following values, or > multiply them by a specific factor: > > agents[which(agent$membership == 1)] > > how would I do this please? > > If there was just one value to manipulate I'd just do this: > > value <- value + 1 > > and this would let me set the values: > > agents[which(agent$membership == 1)] <- 100 > > but how to essentially achieve this: > > agents[which(agent$membership == 1)] <- agents[which(agent$membership == > 1)] + 1 Did you try that? I'd do it without the which() because I'm lazy, but it should work. -- Sarah Goslee http://www.stringpage.com http://www.sarahgoslee.com http://www.functionaldiversity.org [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.