similar to: Appending elements according to criteria to an empty array

Displaying 20 results from an estimated 20000 matches similar to: "Appending elements according to criteria to an empty array"

2012 Mar 22
2
Randomly select elements based on criteria
Hi, I want to randomly pick 2 fish born the same day but I need those individuals to be from different families. My table includes 1787 fish distributed in 948 families. An example of a subset of fish born in one specific day would look like: >fish fam born spawn 25 46 43 25 46 56 26 46 50 43 46 43 131 46 43 133 46 64 136 46 43 136 46 42 136 46 50 136 46 85 137 46 64 142 46 85 144 46 56
2011 Feb 13
2
Removing elements from a vector matching a criteria, BUG in which() function
Dear all, I found a bug in the which() function. When trying to remove elements with the which function, if the criteria is not matched, numeric(0) is returned instead of the array itself. This is very weird. > a = c(1,2,3,4,5) > a[!a==6] [1] 1 2 3 4 5 > a[-which(a==6)] numeric(0) > a[-which(a==5)] [1] 1 2 3 4 > a[!a==5] [1] 1 2 3 4 Is this correct? I believe this is a bug. I
2009 Aug 01
2
Add columns in a dataframe and fill them from another table according to a criteria
Deare R users I am new to R. What I want to do is explained below;- I have table called States.Prob which is given below:- This table gives the probabilities of the changes in the swap curve depending on the state of the swap curve. I want to put these probabilities in my dataframe mydata(given after the prob table). Prob of States Changes State1 State2 State3 State4 a
2009 Aug 27
5
Help on efficiency/vectorization
Dear R users, I am trying to extract the rownames of a data set for which each columns meet a certain criteria. (condition - elements of each column to be equal 1) I have the correct result, however I am seeking for more efficient (desire vectorization) way in implementing such problem as it can get quite messy if there are hundreds of columns. Arbitrary data set and codes are shown below for
2010 Oct 22
1
Problem with Aggregate - Sum, limit on number of criteria
Hello, It appears there is a limit in the number of criteria that can be put into the Aggregate sum function. (It looks like it is 32). My code is; HSfirst=aggregate(count,
2013 Jun 07
1
relist() is broken when the skeleton is a list with empty list elements
Hi, relist() is broken when the skeleton is a list with empty list elements: > x <- list(1:3, integer(0), 11:14) > relist(unlist(x), x) [[1]] [1] 1 2 3 [[2]] [1] 11 3 [[3]] [1] 11 12 13 14 Hard to believe that such a bug has been around for 6 years (i.e. since the introduction of relist()) without ever being noticed. Cheers, H. > sessionInfo() R
2003 Jun 09
2
Appending elements to an array
Hi all, I am having a bit of trouble with the array structure of R. What I want to do is dynamically add/remove elements to an array. For example: Let's say I have created an array: > myArray <- array(c(3,8), dim=c(1,2)) > myArray [,1] [,2] [1,] 3 8 And I now want to, for example, push an element (5,6) on to this array so it will read: [,1] [,2] [1,] 3 8
2009 Sep 11
2
Accumulating results from "for" loop in a list/array
Dear R users, I would like to accumulate objects generated from 'for' loop to a list or array. To illustrate the problem, arbitrary data set and script is shown below, x <- data.frame(a = c(rep("n",3),rep("y",2),rep("n",3),rep("y",2)), b = c(rep("y",2),rep("n",4),rep("y",3),"n"), c =
2008 Jun 17
1
array elements incorrect
Hello everyone, I have a question as to what code should be used if one wanted to subset from a dataframe of 7000rows by 38 columns.For example if you wanted to generate a array of 100 by 38 would you not use the following: Z<-(dat,dim=c(100,38)) where dat is the dataframe of 7000by 38 Whenever I do this and type show(Z) I get a output of 100 by 38 they all say "integer,7000" as
2010 Dec 27
2
Finding indexes of minum and maximum elements of an array
Hello there I wish to get the "coordinates" of the minimum element of an array. For example, if the array were > H = array(c(8:5,1:4),dim=c(2,2,2)) > H , , 1 [,1] [,2] [1,] 8 6 [2,] 7 5 , , 2 [,1] [,2] [1,] 1 3 [2,] 2 4 then > min(H) [1] 1 and > max(H) [1] 8 Say "idx" were the function I'm looking for. Then, what
2009 Jul 31
1
Fill dataframe from a table according to a criteria
Deare R users I am new to R. What I want to do is explained below;- I have table called States.Prob which is given below Prob of States Changes State1 State2 State3 State4 A Pa1 Pa2 Pa3 Pa4 B Pb1 Pb2 Pb3 Pb4 C Pc1 Pc2 Pc3 Pc4 D Pd1 Pd2 Pd3 Pd4 and I have a dataframe called
2011 Nov 16
1
Replacing values in matrix/dataframe according to changing criteria
Hi there, I am doing some network analysis working with k-cliques and over time I want to see what nodes are members of what cliques and how big these cliques are. I have managed to produce a matrix which shows which k-cliques each node is part of over the 100 time periods (slow though) but I cannot seem to calculate the size of each k-clique which is actually just a count. Basically I have a
2007 Aug 17
1
[BioC] function to find coodinates in an array
The arr.ind in the which function does the job very nicely!!! Thank you everyone for the suggestions! Ana > > >---- Mensaje Original ---- >De: marc_schwartz at comcast.net >Para: m_olshansky at yahoo.com >Asunto: Re: [BioC] [R] function to find coodinates in an array >Fecha: Thu, 16 Aug 2007 21:53:44 -0500 > >>If I am correctly understanding the problem, I think
2010 May 26
1
data frame manipulation change elements meeting criteria
Dear group, Here is my df : trade <- structure(list(Trade.Status = c("DEL", "INS", "INS"), Instrument.Long.Name = c("SUGAR NO.11", "CORN", "CORN"), Delivery.Prompt.Date = c("Jul/10", "Jul/10", "Jul/10"), Buy.Sell..Cleared. = c("Sell", "Buy", "Buy"), Volume = c(1L, 2L,
2012 Mar 30
2
Finding the maximum elements in an array/matrix
Hello, I would like to find the maximum element in a matrix or an array but it does not return what I want. For example, If I have a 2*2 matrix A whose maximum element is the A(1,2). I would like the answer (1,2), but it returns 3, which is the ordinal if one counts by columns. Is there any function that returns (1,2)? Thanks > A<-rbind(c(1,4), c(3,2))> A [,1] [,2] [1,]
2005 Oct 17
2
how to find indices of particular array elements
Dear R helpers, I have a largish matrix (1300 x 1300) and I wish to find the row and column numbers that identify particular elements whose values I know in advance (for example, the row and column numbers for the maximum value of the matrix). I have looked in the help manual and found the functions 'row' and 'col' for finding the indices of a matrix. But, I can't figure out
2009 Sep 07
2
using an array of strings with strsplit, issue when including a space in split criteria
Dear all, I'm having a problem understanding why a split does not occur with in the 2nd use of the function strsplit below: # text strings > txt <- c("sales to 23 August 2008 published 29 August", + "sales to 6 September 2008 published?11 September") # first use > strsplit(txt, 'published', fixed=TRUE) [[1]] [1] "sales to 23 August 2008 "
2005 Apr 19
2
indexing an array using an index-array, but one entry being ', '
Hi I have the following array: test <- array(c(1:16), dim = c(3,4,3)) test ## I call some enries using an index array test.ind <- array(rbind(c(1,2,1), c(3,3,2)), dim = c(2,3)) test[test.ind] ## suppose I want all values in the 2nd row and 4th col over ## all three 3rd dimensions test[2,4,] how to specify a test.ind array with the last index left with ',' i.e test.ind should be
2012 Aug 17
3
Apply a function according to factor levels.
Dear all, I have a question on applying a function to the data according to factor levels. For example, for the data below, what is the best way to apply a function to "values" according to different levels of "samples" (1,2,3,4,5)? values ind sample 1 0.03325 1 1 2 0.03305 1 1 3 0.03185 1 1 4 0.03515 1 1 5 0.03375 1 1 6 0.01180
2011 Feb 21
3
Subset according to groups NA proportion within specific variables
Dear R-List, I have a dataframe with one grouping variable (x) and three response variables (y,z,w). df<-data.frame(x=c(rep(1,3),rep(2,4),rep(3,5)),y=rnorm(12),z=c(3,4,5,NA,NA,NA,NA,1,2,1,2,1),w=c(1,2,3,3,4,3,5,NA,5,NA,7,8)) >df      x            y            z     w      1      0.29306106  3      1      1      0.54797780  4      2      1     -1.38365548  5      3      2     -0.20407986