similar to: apply(ing) to sum subset of a vector

Displaying 20 results from an estimated 30000 matches similar to: "apply(ing) to sum subset of a vector"

2007 Aug 27
1
use apply function with which
Dear R-users, For a data frame (say in this example X) I want to look up the corresponding value in a 'look-up data frame' (in this example Y). The for-loop works but is very time-consuming because 'X' in reality is very big. Therefore I would like to have a solution with apply. However, I do not succeed. Any suggestions? Thanks in advance, Hanneke
2010 Dec 01
3
RFC: sapply() limitation from vector to matrix, but not further
sapply() stems from S / S+ times and hence has a long tradition. In spite of that I think that it should be enhanced... As the subject mentions, sapply() produces a matrix in cases where the list components of the lapply(.) results are of the same length (and ...). However, it unfortunately "stops there". E.g., if you *nest* two sapply() calls where the inner one produces a matrix, very
2011 Feb 20
1
Conditional sum
Hi, I have a DF like this: DF = data.frame(read.table(textConnection(" A B C 1 b1 1999 0.25 2 c1 1999 0.25 3 d1 1999 0.25 4 a2 1999 0.25 5 c2 1999 0.25 6 d2 1999 0.25 7 a3 1999 0.25 8 b3 1999 0.25 9 d3 1999 0.25 10 a4 1999 0.25 11 b4 1999 0.25 12 c4 1999 0.25 13 b1 2001 0.5 14 a2 2001 0.5 15 b1 2004 0.33 16 c1 2004 0.33 17 a2 2004 0.33 18 c2 2004
2013 Mar 14
2
Modifying a data frame based on a vector that contains column numbers
Hello! # I have a data frame: mydf<-data.frame(c1=rep(NA,5),c2=rep(NA,5),c3=rep(NA,5)) # I have an index whose length is always the same as nrow(mydf): myindex<-c(1,2,3,2,1) # I need c1 to have 1s in rows 1 and 5 (based on the information in myindex) # I need c2 to have 1s in rows 2 and 4 (also based on myindex) # I need c3 to have 1 in row 3 # In other words, I am trying to achieve this
2006 Nov 13
1
Question on applying vectors to data.frames by row
# Newbie alert # I am wanting to multiply the rows in a dataframe by a vector. # However, the default behavior appears to be for the vector to be applied # column wise. For example: vct <- 1:4 df <- data.frame(c1 = 5:10, c2= 6:11, c3=7:12, c4=8:13) multTheTwo <- vct * df multTheTwo # This results in the vector getting cycled columnwise # c1 c2 c3 c4 # 1 5 18 7 24 # 2 12 28 16 36 # 3
2015 Dec 19
2
[PATCH] nvc0: add hardware ETC2 and ASTC support where possible
These are supported on GK20A and GM107. Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu> --- Was a bit torn on where to place the enums... we're about to gut all the xml definitions so this seemed appropriate for now. Tested on GK20A only. src/gallium/drivers/nouveau/nv50/nv50_formats.c | 64 +++++++++++++++++++++++++ src/gallium/drivers/nouveau/nvc0/nvc0_screen.c | 10 ++++
2016 Feb 15
1
[PATCH 09/23] nv50-: separate vertex formats from surface format descriptions
Why not fix the new names instead to be like the old names? Seems like that would be way simpler... On Feb 15, 2016 12:38 AM, "Ben Skeggs" <skeggsb at gmail.com> wrote: > From: Ben Skeggs <bskeggs at redhat.com> > > We've previously had identical naming between vertex and texture > formats, so it mostly made sense to define these together. > > However,
2015 Apr 15
2
[LLVMdev] Instruction combiner multiplication canonicalization
Hi, I observed below behavior with Instruction combiner (visitMul Canonicalization) It tries to convert "(X+C1)*C2" to "X*C2+C1*C2" While transforming if operation is guaranteed to not overflow it does not reflect same property to transformed instructions. Consider following scenarios: 1) If input is ((X+C1)*C2)<nsw> Then post canonicalization output should be
2018 Mar 12
0
subsetting comparison problem
> On Mar 11, 2018, at 3:32 PM, Neha Aggarwal <aggarwalneha2000 at gmail.com> wrote: > > Hello All, > I am facing a unique problem and am unable to find any help in R help pages > or online. I will appreciate your help for the following problem: > I have 2 data-frames, samples below and there is an expected output > > R Dataframe1: > C1 C2
2011 Oct 12
3
Applying function to only numeric variable (plyr package?)
My data frame consists of character variables, factors, and proportions, something like c1 <- c("A", "B", "C", "C") c2 <- factor(c(1, 1, 2, 2), labels = c("Y","N")) x <- c(0.5234, 0.6919, 0.2307, 0.1160) y <- c(0.9251, 0.7616, 0.3624, 0.4462) df <- data.frame(c1, c2, x, y) pct <- function(x) round(100*x, 1) I want to
2008 Aug 13
5
subsetting matrix according to columns with character index
Hi, I have a long matrix of the following form which I would like to subset according to the third column: [x y z]: a1 c1 1 a1 c1 2 a2 c1 1 a1 c2 1 a1 c2 2 . . . The first two columns a characters ai and cj. I would like to keep all the rows where there are two entries for z, 1 and 2. That is, I want: a1 c1 1 a1 c1 2 a1 c2 1 a1 c2 2 . . . I try to use something like
2009 Jul 01
1
How should I denormalise a data frame list of lists column?
Hi, I have a data frame where one column is a list of lists. I would like to subset the data frame based on membership of the lists in that column and be able to 'denormalise' the data frame so that a row is duplicated for each of its list elements. Example code follows: # The data is read in in this form with the c2 list values in single strings which I then split to give lists: > f1
2012 Apr 04
2
Selecting obs within groups defined by 2 variables
Hello, I am relatively new to R, and I am trying to select the last observation within a group, where the group is defined by two variables. One of the variables is a date. In the below example, C3 varies within C2, which varies within C1. I need to select the last observation in C3 for 4 groups (C1*C2): 1x, 1y, 2x, and 2y. In my real dataset, C2 is a date (mm/dd/yy) C1 C2 C3 1 x 1 1
2013 Apr 26
2
speed of a vector operation question
Hello, I am dealing with numeric vectors 10^5 to 10^6 elements long. The values are sorted (with duplicates) in the vector (v). I am obtaining the length of vectors such as (v < c) or (v > c1 & v < c2), where c, c1, c2 are some scalar variables. What is the most efficient way to do this? I am using sum(v < c) since TRUE's are 1's and FALSE's are 0's. This
2005 Oct 18
6
Subsetting a list
Colleagues, I have created a list in the following manner: TEST <- list(c("A1", "A2"), c("B1", "B2"), c("C1", "C2")) I now want to delete one element from the list, e.g., the third. The command TEST[[3]] yields (as expected): [1] "C1" "C2" The command TEST[[-3]] yields: Error:
2012 Jul 10
1
cbind and cbind.data.frame
## Hi, I'm having trouble understanding how the cbind function decides what method to apply to its arguments. Easy cut and paste code below. > > > > ## create two columns > c1 <- c("A","A","B","B") > c2 <- 1:4 > > ## cbind outputs a matrix with elements that are characters, seems reasonable > out <-
2007 May 21
1
list element names in S4 class extending list
can list names attributes be preserved through S4 class containment? seems to be so but only if the containment relationship is direct ... see below. > setClass("c1", contains="list") [1] "c1" > l1 = list(a=1, b=2) > o1 = new("c1", l1) > names(o1) # pleasant surprise [1] "a" "b" > setClass("c2",
2007 Aug 23
1
Expedite scalar f(x) evaluation over vectors
Dear R community, I am trying to code a fairly complex equation for optim(). My current approach is too slow for optim(). I have a function that takes a double integral (hopefully correctly) across two terms, e.g., doubleint <- function(c1,c2) {integrate(function(y) { sapply(y, function(y) { integrate(function(x) {a*(c1+x)+b*(c2+x)}, boundsx[1], boundsx[2])$value }) },
2011 Dec 20
5
Help with code
hello gurus, i have a data frame like this HTN HTN_FDR Dyslipidemia CAD t1d_ptype[1:25] 1 Y Y Y T1D 2 T1D 3 Ctrl_FDR 4 T1D 5 Y Ctrl 6 Ctrl 7
2008 Jul 07
2
Colour clusters in a 2d plot
R experts, I have three columns. c1 and c2 are numeric variables whereas c3 are the clusters classes (nominal variable, 10 different: cluster1, cluster2, cluster3, cluster4, cluster5 ....). I'd like to plot c1 against c2 (easy!) in a 2D plot and put different color depending to the cluster class automatically regardless the number of clusters. Could anyone give a hand? Josep Maria, matrix