This should be an easy one, but I haven't been able to figure it out, x<-c(2, 4, 6, 9, 10) #how do I remove a single value x<-x[-2] # will remove the second element of the vector not the number 2 This is part of a loop that looks a little like this... x<-c(2, 4, 6, 9, 10) remove.value<-4 #then I need to remove the value returned by the loop. Thanks, Josh -- View this message in context: http://www.nabble.com/Remove-a-number-from-a-vector-tp16119616p16119616.html Sent from the R help mailing list archive at Nabble.com.
?which x <- x[which(x==remove.value)] --- Josh Roofchop <josh at roofchop.com> wrote:> > This should be an easy one, but I haven't been able > to figure it out, > > x<-c(2, 4, 6, 9, 10) > #how do I remove a single value > x<-x[-2] # will remove the second element of the > vector not the number 2 > > This is part of a loop that looks a little like > this... > > x<-c(2, 4, 6, 9, 10) > remove.value<-4 > #then I need to remove the value returned by the > loop. > > Thanks, > Josh > > -- > View this message in context: >http://www.nabble.com/Remove-a-number-from-a-vector-tp16119616p16119616.html> Sent from the R help mailing list archive at > Nabble.com. > > ______________________________________________ > R-help at 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. >
does> x[!x == remove.value]do what you need? [1] 2 6 9 10 regards, Albert Am Dienstag, den 18.03.2008, 05:21 -0700 schrieb Josh Roofchop:> This should be an easy one, but I haven't been able to figure it out, > > x<-c(2, 4, 6, 9, 10) > #how do I remove a single value > x<-x[-2] # will remove the second element of the vector not the number 2 > > This is part of a loop that looks a little like this... > > x<-c(2, 4, 6, 9, 10) > remove.value<-4 > #then I need to remove the value returned by the loop. > > Thanks, > Josh >
Thanks to both John and Arthur for their replies, they both worked great. Josh Josh Roofchop wrote:> > This should be an easy one, but I haven't been able to figure it out, > > x<-c(2, 4, 6, 9, 10) > #how do I remove a single value > x<-x[-2] # will remove the second element of the vector not the number 2 > > This is part of a loop that looks a little like this... > > x<-c(2, 4, 6, 9, 10) > remove.value<-4 > #then I need to remove the value returned by the loop. > > Thanks, > Josh > >-- View this message in context: http://www.nabble.com/Remove-a-number-from-a-vector-tp16119616p16121649.html Sent from the R help mailing list archive at Nabble.com.
Seemingly Similar Threads
- Does the rsync/xdelta algorithm *need* to write a new file?
- Automating migration of files from windows to samba
- substituting elements in vector according to sample(unique(vector))
- Wildcard expansion in remote files or recursion?
- samba 4.7.0 replication errors