[R] Fastest way to compare a single value with all values in one column of a data frame
smartpink111 at yahoo.com
Wed Jan 30 15:22:14 CET 2013
I guess you could also use:
# item a b
#1 f 3 10
#2 b 2 12
#3 c 3 13
#4 d 4 14
#5 e 5 15
----- Original Message -----
From: Dimitri Liakhovitski <dimitri.liakhovitski at gmail.com>
To: r-help <r-help at r-project.org>
Sent: Tuesday, January 29, 2013 4:11 PM
Subject: [R] Fastest way to compare a single value with all values in one column of a data frame
I have a large data frame x:
x<-data.frame(item=letters[1:5],a=1:5,b=11:15) # in actuality, x has 1000
I also have a small data frame y with just 1 row:
I have to decide if y$a is larger than the smallest of all the values in
x$a. If it is, I want y to replace the whole row in x that has the lowest
value in column a.
This is how I'd do it.
I am wondering if there is a faster way of doing it. What would be the
fastest possible way? I'd have to do it, unfortunately, many-many times.
Thank you very much!
[[alternative HTML version deleted]]
R-help at r-project.org mailing list
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