similar to: Sum of Numeric Values in a DF Column

Displaying 20 results from an estimated 2000 matches similar to: "Sum of Numeric Values in a DF Column"

2016 Apr 18
2
Sum of Numeric Values in a DF Column
... and here is a non-dplyr rsolution: > z <-gsub("[^[:digit:]]"," ",dd$Lower) > sapply(strsplit(z," +"),function(x)sum(as.numeric(x),na.rm=TRUE)) [1] 105 67 60 100 80 Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom
2016 Apr 18
0
Sum of Numeric Values in a DF Column
## Continuing with your data AA <- stringr::str_extract_all(dd[[2]],"[[:digit:]]+") BB <- lapply(AA, as.numeric) ## I think you are looking for one of the following two expressions sum(unlist(BB)) sapply(BB, sum) On Mon, Apr 18, 2016 at 12:48 PM, Burhan ul haq <ulhaqz at gmail.com> wrote: > Hi, > > I request help with the following: > > INPUT: A data frame
2016 Apr 18
0
Sum of Numeric Values in a DF Column
... and a slightly more efficient non-dplyr 1-liner: > sapply(strsplit(dd$Lower,"[^[:digit:]]"), function(x)sum(as.numeric(x), na.rm=TRUE)) [1] 105 67 60 100 80 Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On
2013 Nov 28
1
Relative Cumulative Frequency of Event Occurence
Hi, My objective is to calculate "Relative (Cumulative) Frequency of Event Occurrence" - something as follows: Sample.Number 1st.Fly 2nd.Fly Did.E.occur? Relative.Cum.Frequency.of.E 1 G B No 0.000 2 B B Yes 0.500 3 B G No 0.333 4 G B No 0.250 5 G G Yes 0.400 6 G B No 0.333 7 B B Yes 0.429 8 G G Yes 0.500 9 G B No 0.444 10 B B Yes 0.500 Please refer to the code below:
2012 Feb 09
3
how to exclude rows with not-connected coalitions
Dear all, I have question but cannot explain without providing some context first: I want to calculate how many policy-connected coalitions between 7 parties are possible. I have positions on an one-dimensional scale for each party and I have sorted the parties on the positions (it is sorted from extreme left to extreme right, hence using a left-right scale). A policy-connected coalition
2012 Jun 15
1
help in sentDetect() fuction
hello, I am using the following code >s<-"I am very happy, excited, and optimistic.I am very scared, annoyed, and irritated.Iraq?s political crisis entered its second week one step closer to the potential.dissolution of the government, with a call for elections by a vital coalition partner and a suicide attack that extended the spate of violence. that has followed the withdrawal.of
2009 Oct 30
1
Package zelig
hello all I am using the R package Zelig for some tobit regression with robust standard errors. I have got R version 2.9.2 (2009-08-24) and Zelig Version: 3.4-5 when i do demo(robust) It ends like this way data(coalition) > # Fit the model with robust standard error > user.prompt() Press <return> to continue: > z.out3 <- zelig(Surv(duration, ciep12) ~ polar + numst2 +
2009 Nov 13
3
sum(row1==y) if row2=x
Hi to all is there any construct to sum data=data.frame(row1=c(1,1,3,1,2,3,2,2,1,3,4,5,2,3,2,1) , row2=c(2,2,1,1,1,2,1,2,1,1,1,1,2,2,2,1) ) Means I would like to get all y of row1 if in row2 of the data.frame is an x f.e row1=3 and row2=2 so I would like to get 6 And is there another construct to get the count of pairs where row1=3 and row2=2 means the result should be
2011 Oct 13
3
US States percentage change plot
Hi, I would like to make a plot of the US states (or lower 48) that are colored based upon a percentage change column. Ideally, it would gradually be more blue the larger the positive change, and more red the more negative is the change. The data I have looks like: State Percent.Change 1 Alabama 0.004040547 2 Alaska -0.000202211 3 Arizona -0.002524567 4 Arkansas
2012 May 08
1
Extracting Hash-tagged word from Tweets
Can someone help me with the code I can use to extract word preceded by hash tag in live tweets download from twitteR. An example of what I require is: [[9]] [1] "HollandUKTrade: #Dutch companies striking Olympic gold at London 2012 http://t.co/XsvvXAzT #london2012 #olympics #sport @hollandtrade @dutchembassyUK" (Tweet download) I want a code that will extract this: #Dutch companies
2011 Jul 23
2
sum part of a vector
Dear colleagues, I have a data set that looks roughly like this; mydat<-data.frame(state=c(rep("Alabama", 5), rep("Delaware", 5), rep("California", 5)), news=runif(15, min=0, max=8), cum.news=rep(0, 15)) For each state, I'd like to cumulatively sum the value of "news" and make that put that value in cum.news. I'm trying as follows but I get
2009 Jul 03
2
mapping states with colors
Hi folks, I'm just learning how to use maps. As an initial foray, I'm mapping the states that have "duty to retreat" (blue) and "stand your ground" (red) self-defense standards. Here is my extremely naive script: dtr <- c('alabama', 'arizona', 'conneticut', 'delaware', 'dist of columbia' , 'hawaii',
2006 Jul 08
6
Trying to create pulldown select menu for US State form fiel
I noticed there is a country_select. Is there anything like us_state_select maybe? More specifically - I''m wondering if I manually have to populate an array with all the U.S. state abbreviations so users can select which state they live in while entering their mailing address. -- Posted via http://www.ruby-forum.com/.
2013 Jun 16
2
extract all numbers from a string
Hi all, I have been beating my head against this problem for a bit, but I can't figure it out. I have a series of strings of variable length, and each will have one or more numbers, of varying format. E.g., I might have: tmpstr = "The first number is: 32. Another one is: 32.1. Here's a number in scientific format, 0.3523e10, and another, 0.3523e-10, and a negative,
2009 Aug 27
1
generating multiple sequences in subsets of data
I'm running into a problem I can't seem to find a solution for. I'm attempting to add sequences into an existing data set based on subsets of the data. I've done this using a for loop with a small subset of data, but attempting the same process using real data (200k rows) is taking way too long. Here is some sample data and my ultimate goal >
2008 Dec 16
1
refer to next line within a data-frame an select cases
Hi, I have a problem sorting and selecting entries within a data-frame and I don't know if it is possible to solve it with R ... (probably yes, but I have no idea how). Following Data; row1 row2 a 12 pos NA a 3 neg NA a 5 neg NA a 11 pos NA I want to extract the values in row 2 in the lines with an "a" in row1. But I want to have two vectors: vector x with all
2010 May 11
1
create a data.frame for aov
Hi R-experts, I try to find a way to transfer a matrix to a data.frame that is used as input of aov. can you give me advice for that? >mdat <- matrix(c(1,2,3, 11,12,13), nrow = 2, ncol=3, byrow=TRUE, dimnames = list(c("row1", "row2"), c("Col1", "Col2", "Col3"))) >mdat      Col1 Col2 Col3 row1    1    2    3 row2   11   12   13 ===>
2005 May 05
3
body of non-visible function
Hello, Is there any possibility in R to see the body of the non-visible function, for example princomp? If I do : > methods(princomp) so, I get that princomp.default and princomp.formula are non-visible functions and body(princomp.default) doesnt show it. In particular, I guess I have a very nave question Id like to see how scores calculation is implemented in the function princomp.
2005 Nov 28
7
combine two columns
Hi, I have an R programming problem and I havent found anything in the documentation yet: I have a data matrix, in which two neighbouring columns represent replicates of the same experiment, e.g. something like this: A A B B C C row1 1 1 1 2 2 2 row2 1 1 1 1 1 2 I would like to test, if the values for the two replicates in a row are the same or if they differ and generate a new
2012 Aug 03
3
embedding data frame in R code?
I would like to insert a few modest size data frames directly into my R code. a short illustration example of what I want is d <- read.csv( _END_, row.names=1 ) , "col1", "col2" "row1",1,2 "row2",3,4 __END__ right now, the data sits in external files. I could put each column into its own vector and then combine into a data frame, but this seems