Re: [R] function for filtering and deleting vector entries
Thank you Rui, that helped a lot. The correct values show up when I'm using the following code. Now fun(Temp,v) returns a matrix, and Temp and v stay the same. But I'd like to use the reduced vectors in some calculations..can they be extracted in some way so that I have them separately again? fun - function(Temp, v){ unwanted - Temp = 16 | Temp = 38.5 Temp - Temp[!unwanted] v - v[!unwanted] list(Temp=Temp, v=v) } fun(Temp,v) PS: thank you too,andrija..but it's not what I'm looking for -- View this message in context: http://r.789695.n4.nabble.com/function-for-filtering-and-deleting-vector-entries-tp4432410p4436217.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.
Re: [R] function for filtering and deleting vector entries
Of course, just use x - fun(Temp, v) x$Temp # To get back temp x[[Temp]] x$v # To get back v x[[v]] Michael On Thu, Mar 1, 2012 at 3:15 PM, babyluck madr...@gmx.ch wrote: Thank you Rui, that helped a lot. The correct values show up when I'm using the following code. Now fun(Temp,v) returns a matrix, and Temp and v stay the same. But I'd like to use the reduced vectors in some calculations..can they be extracted in some way so that I have them separately again? fun - function(Temp, v){ unwanted - Temp = 16 | Temp = 38.5 Temp - Temp[!unwanted] v - v[!unwanted] list(Temp=Temp, v=v) } fun(Temp,v) PS: thank you too,andrija..but it's not what I'm looking for -- View this message in context: http://r.789695.n4.nabble.com/function-for-filtering-and-deleting-vector-entries-tp4432410p4436217.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.
Re: [R] function for filtering and deleting vector entries
Thank you very much!! Exactly how I wanted it :) -- View this message in context: http://r.789695.n4.nabble.com/function-for-filtering-and-deleting-vector-entries-tp4432410p4436303.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] function for filtering and deleting vector entries
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@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.
Re: [R] function for filtering and deleting vector entries
Hi. Maybe this will help you: set.seed(1) temp - 1:100 v - rnorm(100) temp[temp16 | temp38] v[temp16 | temp38] Andrija On Wed, Feb 29, 2012 at 7:09 PM, babyluck madr...@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@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.
Re: [R] function for filtering and deleting vector entries
Hello, babyluck 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) } } Your function is not changing 'Temp' nor 'v', just choosing subsets of them. And you 'return' at the end of the first iteration... (And you can only return one value) Try fun - function(Temp, v){ unwanted - Temp = 16 | Temp = 38.5 Temp - Temp[!unwanted] v - v[!unwanted] list(Temp=Temp, v=v) } (tt - seq(10, 40, by=0.5)) (vv - 1:length(tt)) fun(tt, vv) I've changed the name because 'norm' is a R function name. See ?norm Hope this helps, Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/function-for-filtering-and-deleting-vector-entries-tp4432410p4432772.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.