[R] function for filtering and deleting vector entries

andrija djurovic djandrija at gmail.com
Wed Feb 29 23:28:34 CET 2012


Hi.

Maybe this will help you:

set.seed(1)
temp <- 1:100
v <- rnorm(100)

temp[temp<16 | temp>38]
v[temp<16 | temp>38]

Andrija

On Wed, Feb 29, 2012 at 7:09 PM, babyluck <madruga at gmx.ch> wrote:
> Dear helpers
>
> I have two data sets saved as vectors (temperature and velocity). Now I need
> to "take out" a span of temperature and its corresponding velocity in the
> other vector. How can I achieve that?
>
> I tried to write a function,which takes a vector entry and then decides
> wether to delete the temperature entry or not and  simultaneously doing so
> with same entry in the velocity vector..
> But somehow it's not working...could somebody please help me?
> Thanks a lot..
>
>
> norm = function(Temp,v){
>        for (i in 1:length(Temp)){
>
>                if (Temp[i]<=16 || Temp[i] >= 38.5)
>                 {Temp[-i];v[-i]}
>
>                return(Temp,v)
>        }
> }
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/function-for-filtering-and-deleting-vector-entries-tp4432410p4432410.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.



More information about the R-help mailing list