Displaying 18 results from an estimated 18 matches similar to: "extract value from first column based on value in second column"
2009 Mar 25
3
Converting a Matrix to a Vector
Say I have:
> set.seed( 1 )
> m <- matrix( runif(5^2), nrow=5, dimnames = list( c("A","B","C","D","E"),
> c("O","P","Q","R","S") ) )
> m
O P Q R S
A 0.2655087 0.89838968 0.2059746 0.4976992 0.9347052
B 0.3721239 0.94467527 0.1765568
2010 Nov 07
2
remove data frame from list of data frames
I have a list of data frames like this:
a<- data.frame(x=runif(10), y = runif(10), Acc = 1)
b<- data.frame(x=runif(10), y = runif(10), Acc = 0)
ls<- list(a,b)
and I want to remove the data frames from ls that have Acc values other than 1.
How do I do that?
Thanks for any help!
Matthew
2010 May 28
3
how to create automatically names for vectors in a loop?
Hi,
I want to generate a number of vectors and store them with different names, like this:
x=1
while (x<100)
{
vector#x# = rnorm(100)
x=x+1
}
where each vector has, at its hand, instead of #x# a number which goes from 1 to 99.
How can I do this?
Thanks
Gabriele Zoppoli, MD
Ph.D. Fellow, Experimental and Clinical Oncology and Hematology, University of Genova, Genova, Italy
Guest
2004 Nov 29
2
[BASIC] Solution of creating a sequence of object names
Dear R-users,
I state that this is for beginners, so you may ignore
this in order not to be irritated.
By the way, "patience" is another important thing,
together with "kindness", we should keep in mind when
we teach students and our own children as Jim Lemon
pointed out well in the context of the Socratic
method. You may know that being kind does not mean
giving
2007 Mar 03
1
function doesnt return/create object
hello,
i have written a function to extract certain lines from a matrix. the
result is a matrix with 6 cols, named dynamically according to the
functions arguments.
the problem is now, that i'm not able to return the resultmatrix for
further use. the object is not being created.
example from my console:
getans(27,27)
[...]
[189,] 3969 161 27 1 0 1
[190,] 2142 87 27
2008 Sep 05
5
Lowest k values of list
Hi @ all,
how do I get the largest or lowest k values of list? It must similar to the min() / max() function, but I just don't get it.
Best wishes,
Markus
2009 May 25
1
Memory problems when using ifelse
Dear R Users,
I have a data frame of 4 columns and ~58000 rows, the top of which looks like this:
> head(max_out)
Latitude Longitude Model Obs
1 -0.25 -49.25 4 4
2 -0.25 -50.25 4 5
3 -0.25 -50.75 4 4
4 -0.25 -51.25 3 11
5 -0.25 -51.75 6 4
6 -0.25 -52.25 12 5
The above shows, for each coordinate point, the
2010 Mar 15
5
storing matrix(variables) in loop
Hello R-helpers,
I have the following code that works well,
b <-list()
for (i in 1:3){
a <- matrix(runif(1),3,3)
b[[i]] <- a
}
b
however, I need to do something similar with two loops and I was looking for
something that would look like
b <- list()
for (i in 1:3){
for (j in 1:4){
a <- matrix(runif(1),3,3)
b[[i,j]] <- a #but this doesn?t work
}
}
Anyway, I wanted
2010 Jul 19
2
replacing elements of distance matrix
Hi! I am trying to implement non-bipartite matching. I have around 500 sites
which can be clustered by 10 regions. I am able to calculate pairwise
Mahalanobis distances between sites (thanks to another post in the forum).
However, I want to constrain my match to sites within the same region. Thus
I want to replace elements of the distance matrix with a high value, say
999999, for sites not of the
2008 Sep 09
1
how to split a data framed with sequences
Hi all,
Given a data frame:
my.df <- data.frame(a = c(1:5, 1:10, 1:20), b = runif(35))
I want to split it by "a" such that I end up with a list containing 3
components i.e. the first containing a = 1 to 5, the second a = 1 to 10 etc.
In other words, sets of sequences of a.
I can't seem to find the right form using the split function - can you help?
Much appreciated.
David
2011 Aug 08
0
Odp: Fw: R function for Gage R&R
Hi Elaine
I do not use it very often. I programmed it to mimic Minitab functions
(partly) with some adons from czech statistics textbook written by
M.Meloun (meloun militky statistics - first hit in google)
Basically you can have your data in some data frame or they can be as
separated vectors. The function itself expects input of 3 vectors, but you
can easily to modify it for imput as
2013 May 08
4
Correctly Setting New Seed
Could someone please suggest a method to store the current random seed. I'm having trouble understanding how to correctly use set.seed and .Random.seed.
Specifically, I have the following code that crashes:
set.seed(seed)
for(i in 1:10){
print( runif(1))
}
To get around this I need to split the number of iterations into chunks:
set.seed(seed)
for(i in 1:5){
print(runif(1))
2011 Sep 19
1
Binary optimization problem in R
Dear all,
I would like to solve a problem similar to a multiple knapsack problem and
am looking for a function in R that can help me.
Specifically, my situation is as follows: I have a list of n items which I
would like to allocate to m groups with fixed size. Each item has a certain
profit value and this profit depends on the type of group the item is in. My
problem is to allocate the items
2012 Sep 15
2
How to convert the output of tapply() so that it has the same order as the input?
Hi,
I try to apply a function to subsets of a data.frame. tapply() does the job, but
the as output, I am looking for a vector (not an array/matrix) ordered in the
same way as the original data, so I can simply cbind the result to the original
data.frame. Below is a minimal example.
I know that there are packages that can do these things easier, but I'm looking
for a fast solution not
2009 Apr 13
2
weighted mean and by() with two index
Hi expeRts,
I would like to calculate weighted mean by two factors.
My code is as follows:
R> tmp <- by(re$meta.sales.lkm[, c("pc", "sales")],
re$meta.sales.lkm[, c("size", "yr")], function(x)
weighted.mean(x[,1], x[,2]))
The result is as follows:
R> tmp
size: micro
yr: 1994
[1] 1.090
2016 Apr 08
0
Is this a bug in quantmod::OpCl?
On 04/06/2016 07:58 PM, Joshua Ulrich wrote:
> On Tue, Apr 5, 2016 at 9:17 PM, James Hirschorn
> <james.hirschorn at hotmail.com> wrote:
>> OpCl works on xts objects but not on quantmod.OHLC objects. Is this a bug?
>>
> Thanks for the minimal, reproducible example.
>
> Looks like a bug. There's no as.quantmod.OHLC.xts method, so the zoo
> method is
2016 Apr 08
0
Is this a bug in quantmod::OpCl?
On Fri, Apr 8, 2016 at 10:51 AM, James Hirschorn
<james.hirschorn at hotmail.com> wrote:
>
>
> On 04/06/2016 07:58 PM, Joshua Ulrich wrote:
>>
>> On Tue, Apr 5, 2016 at 9:17 PM, James Hirschorn
>> <james.hirschorn at hotmail.com> wrote:
>>>
>>> OpCl works on xts objects but not on quantmod.OHLC objects. Is this a
>>> bug?
2008 Oct 15
0
R-help Digest, Vol 67, Issue 31
V;
Sent via BlackBerry from T-Mobile
-----Original Message-----
From: r-help-request at r-project.org
Date: Tue, 30 Sep 2008 12:00:06
To: <r-help at r-project.org>
Subject: R-help Digest, Vol 67, Issue 31
Send R-help mailing list submissions to
r-help at r-project.org
To subscribe or unsubscribe via the World Wide Web, visit
https://stat.ethz.ch/mailman/listinfo/r-help
or, via email,