Re: [R] Removing rows in a data frame

2015-07-03 Thread Rainer Schuermann
Try y - x[ -( 30596:678013 ), ] Please note that I have replaced 30595 with 30596 which is I think what you mean. You can add a new column with y$new - new_column # this is your vector of length 30595 Good luck, Rainer On Friday 03 July 2015 07:23:28 Charles Thuo wrote: I have a data

Re: [R] Removing rows in a data frame

2015-07-03 Thread Sergio Fonda
In my experience package dplyr has all functions to deal with this kind of problems in a simple and compact way Sergio Il 03/lug/2015 07:26, Charles Thuo tcmui...@gmail.com ha scritto: I have a data frame whose rows are 678013 . I would like to remove rows from 30696 to 678013 and then attach

[R] Removing rows in a data frame

2015-07-02 Thread Charles Thuo
I have a data frame whose rows are 678013 . I would like to remove rows from 30696 to 678013 and then attach a new column with a length of 30595. I tried Y- X[-30595:678013,] and its not working In addition how do i add a new column Kindly assist. Charles [[alternative HTML version

Re: [R] Removing rows in a data frame

2015-07-02 Thread Bert Gunter
?precedence -5:10 is (-5):10 -- Bert Bert Gunter Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. -- Clifford Stoll On Thu, Jul 2, 2015 at 10:23 PM, Charles Thuo tcmui...@gmail.com wrote: I have a data frame whose rows are 678013 . I would

[R] Removing rows in a data frame containing string in rownames

2014-11-16 Thread Steven Yen
I like to remove from a data frame rows with labels containing certain string, e.g., sex and rating. Below is a list of the data frame and my failed attempt to the rows. Any clues? Thanks. out est se t p disc p.(Intercept) 26.430 13.605 1.943 0.053 p.sex

Re: [R] Removing rows in a data frame containing string in rownames

2014-11-16 Thread William Dunlap
Try grepl() to do pattern matching in strings. (%in% checks for equality.) E.g., using your original 'out' do out[ !grepl(sex|rating, rownames(out), ] to get all but the rows whose names contain the character sequences sex or rating. Bill Dunlap TIBCO Software wdunlap tibco.com On Sun, Nov

Re: [R] Removing rows in a data frame containing string in rownames

2014-11-16 Thread Steven Yen
Thank you Bill and Dennis. grepl worked great. However, for reason I am not figuring out, the code worked as I included the procedure (subroutine) with a source command, viz., source(z:\\R\\mylib\\me.R) Compiling the routine into a library/package, as I always do, then the command got

Re: [R] Removing rows in a data frame containing string in rownames

2014-11-16 Thread Jeff Newmiller
Not clear what you did. Is this an example of FAQ 7.16? --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go...

[R] Removing rows w/ smaller value from data frame

2013-05-23 Thread ramoss
Hello, I have a column called max_date in my data frame and I only want to keep the bigger values for the same activity. How can I do that? data frame: activitymax_dt A2013-03-05 B 2013-03-28 A 2013-03-28 C 2013-03-28 B 2013-03-01

Re: [R] Removing rows w/ smaller value from data frame

2013-05-23 Thread PIKAL Petr
-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of ramoss Sent: Thursday, May 23, 2013 4:24 PM To: r-help@r-project.org Subject: [R] Removing rows w/ smaller value from data frame Hello, I have a column called max_date in my data frame and I only want to keep

Re: [R] Removing rows w/ smaller value from data frame

2013-05-23 Thread arun
, max_dt=tail(sort(max_dt),1)) #  activity max_dt #1    A 2013-03-28 #2    B 2013-03-28 #3    C 2013-03-28 A.K. - Original Message - From: ramoss ramine.mossad...@finra.org To: r-help@r-project.org Cc: Sent: Thursday, May 23, 2013 10:23 AM Subject: [R] Removing rows w

Re: [R] Removing rows w/ smaller value from data frame

2013-05-23 Thread arun
, Ramine N. ramine.mossad...@finra.org To: arun smartpink...@yahoo.com Cc: Sent: Thursday, May 23, 2013 10:44 AM Subject: RE: [R] Removing rows w/ smaller value from data frame Thank but I get : Error in is.list(by) : 'by' is missing When I tried ddply(datNew,.(activity),summarize, max_dt=max

Re: [R] Removing rows that are duplicates but column values are in reversed order

2013-04-12 Thread arun
Hi, From your example data, dat1- read.table(text= id1   id2   value a  b   10 c  d    11 b a 10 c  e 12 ,sep=,header=TRUE,stringsAsFactors=FALSE) #it is easier to get the output you wanted dat1[!duplicated(dat1$value),] #  id1 id2 value #1   a   b    10

Re: [R] Removing rows that are duplicates but column values are in reversed order

2013-04-12 Thread vpr3
Thanks very much for your rapid help Arun. Vince On Apr 12, 2013, at 4:10 PM, arun kirshna [via R] wrote: Hi, From your example data, dat1- read.table(text= id1 id2 value a b 10 c d11 b a 10 c e 12 ,sep=,header=TRUE,stringsAsFactors=FALSE)

Re: [R] Removing rows if certain elements are found in character string

2012-07-05 Thread MacQueen, Don
Perhaps I've missed something, but if it's really true that the goal is to remove rows if the first non-zero element is D or d, then how about this: tmp - gsub('0','',df$ch) first - substr(tmp,1,1) subset(df, tolower(first) != 'd') and of course it could be rolled up into a single expression,

Re: [R] Removing rows if certain elements are found in character string

2012-07-03 Thread Rui Barradas
Hello, Inline. Em 03-07-2012 01:15, jim holtman escreveu: You will have to change the 'i1' expression as follows: i1 - grepl(^([0D]|[0d])*$, dd$ch) i1 # matches strings with d D in them [1] TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE # second string had 'd' 'D' in it

Re: [R] Removing rows if certain elements are found in character string

2012-07-03 Thread Claudia Penaloza
Thank you Rui and Jim, both 'i1' and 'i1new' worked perfectly because there are no instances of 'Dd' or 'dD' in the data set (that I would/not want to include/exclude)... but I understand that 'i1new' targets precisely what I want. Why isn't a leader of zero's required for either 'i1' or 'i1new',

Re: [R] Removing rows if certain elements are found in character string

2012-07-03 Thread Rui Barradas
Hello, I'm glad it helped. See answer inline. Em 03-07-2012 17:09, Claudia Penaloza escreveu: Thank you Rui and Jim, both 'i1' and 'i1new' worked perfectly because there are no instances of 'Dd' or 'dD' in the data set (that I would/not want to include/exclude)... but I understand that 'i1new'

Re: [R] Removing rows if certain elements are found in character string

2012-07-03 Thread Claudia Penaloza
Got it! Thank you Rui! cp On Tue, Jul 3, 2012 at 10:14 AM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, I'm glad it helped. See answer inline. Em 03-07-2012 17:09, Claudia Penaloza escreveu: Thank you Rui and Jim, both 'i1' and 'i1new' worked perfectly because there are no instances

[R] Removing rows if certain elements are found in character string

2012-07-02 Thread Claudia Penaloza
I would like to remove rows from the following data frame (df) if there are only two specific elements found in the df$ch character string (I want to remove rows with only 0 D or 0 d). Alternatively, I would like to remove rows if the first non-zero element is D or d.

Re: [R] Removing rows if certain elements are found in character string

2012-07-02 Thread Rui Barradas
Hello, Try regular expressions instead. In this data.frame, I've changed row nr.4 to have a row with 'D' as first non-zero character. dd - read.table(text= ch count 1 00D0 0.007368 2 00d0 0.002456 3

Re: [R] Removing rows if certain elements are found in character string

2012-07-02 Thread jim holtman
You will have to change the 'i1' expression as follows: i1 - grepl(^([0D]|[0d])*$, dd$ch) i1 # matches strings with d D in them [1] TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE # second string had 'd' 'D' in it so it was TRUE above and FALSE below i1new -

Re: [R] Removing rows if certain elements are found in character string

2012-07-02 Thread David Winsemius
On Jul 2, 2012, at 6:48 PM, Claudia Penaloza wrote: I would like to remove rows from the following data frame (df) if there are only two specific elements found in the df$ch character string (I want to remove rows with only 0 D or 0 d). Alternatively, I would like to remove rows if the

Re: [R] Removing rows if certain elements are found in character string

2012-07-02 Thread arun
- From: Claudia Penaloza claudiapenal...@gmail.com To: r-help@r-project.org Cc: Sent: Monday, July 2, 2012 6:48 PM Subject: [R] Removing rows if certain elements are found in character string I would like to remove rows from the following data frame (df) if there are only two specific elements

Re: [R] Removing rows if certain elements are found in character string

2012-07-02 Thread arun
: r-help@r-project.org Sent: Monday, July 2, 2012 7:24 PM Subject: Re: [R] Removing rows if certain elements are found in character string Hello, Try regular expressions instead. In this data.frame, I've changed row nr.4 to have a row with 'D' as first non-zero character. dd - read.table(text= ch

[R] Removing rows in dataframe w'o duplicated values

2011-11-22 Thread AC Del Re
Hi, Is there an easy way to remove dataframe rows without duplicated values of a specified column ('id')? e.g., dat - data.frame(id = c(1,1,1,2,3,3), value = c(5,6,7,4,5,4), value2 = c(1,4,3,3,4,3)) dat id value value2 1 1 5 1 2 1 6 4 3 1 7 3 4 2 4 3 5

Re: [R] Removing rows in dataframe w'o duplicated values

2011-11-22 Thread B77S
This is ugly, but it gets what you want. dat[which(dat[,1] %in% unique((dat[duplicated(dat[,1], fromLast = T), 1]))),] AC Del Re wrote Hi, Is there an easy way to remove dataframe rows without duplicated values of a specified column ('id')? e.g., dat - data.frame(id =

Re: [R] Removing rows in dataframe w'o duplicated values

2011-11-22 Thread Dennis Murphy
Hi: Here's one way: do.call(rbind, lapply(L, function(d) if(nrow(d) 1) return(d))) id value value2 1.1 1 5 1 1.2 1 6 4 1.3 1 7 3 3.5 3 5 4 3.6 3 4 3 HTH, Dennis On Tue, Nov 22, 2011 at 9:43 AM, AC Del Re de...@wisc.edu wrote: Hi, Is

Re: [R] Removing rows in dataframe w'o duplicated values

2011-11-22 Thread Dennis Murphy
Sorry, you need this first: L - split(dat, dat$id) do.call(rbind, lapply(L, function(d) if(nrow(d) 1) return(d))) D. On Tue, Nov 22, 2011 at 10:38 AM, Dennis Murphy djmu...@gmail.com wrote: Hi: Here's one way: do.call(rbind, lapply(L, function(d) if(nrow(d) 1) return(d)))    id value

Re: [R] Removing rows in dataframe w'o duplicated values

2011-11-22 Thread Dimitris Rizopoulos
one approach is the following: dat - data.frame(id = c(1,1,1,2,3,3), value = c(5,6,7,4,5,4), value2 = c(1,4,3,3,4,3)) ind - ave(dat$id, dat$id, FUN = length) 1 dat[ind, ] I hope it helps. Best, Dimitris On 11/22/2011 6:43 PM, AC Del Re wrote: Hi, Is there an easy way to remove

Re: [R] Removing rows in dataframe w'o duplicated values

2011-11-22 Thread David Winsemius
On Nov 22, 2011, at 12:43 PM, AC Del Re wrote: Hi, Is there an easy way to remove dataframe rows without duplicated values of a specified column ('id')? e.g., dat - data.frame(id = c(1,1,1,2,3,3), value = c(5,6,7,4,5,4), value2 = c(1,4,3,3,4,3)) dat id value value2 1 1 5 1

Re: [R] Removing rows of zeros from a matrix

2011-06-23 Thread David Winsemius
On Jun 2, 2011, at 11:35 AM, Petr Savicky wrote: On Thu, Jun 02, 2011 at 11:23:28AM -0400, Jim Silverton wrote: Hi, Can someone tell me how to remove rows of zeros from a matrix? For example if I have the following matrix, 0 0 0 1 2 8 0 0 4 56 I should end up with 0 1 2 8 4 56 Hi. Try

Re: [R] Removing rows of zeros from a matrix

2011-06-02 Thread Jim Silverton
Hi, Can someone tell me how to remove rows of zeros from a matrix? For example if I have the following matrix, 0 0 0 1 2 8 0 0 4 56 I should end up with 0 1 2 8 4 56 -- Thanks, Jim. [[alternative HTML version deleted]] __

Re: [R] Removing rows of zeros from a matrix

2011-06-02 Thread Jonathan Daily
Assuming the matrix is named X: X[which(rowSums(X) 0),] should work. Also, this list is a text-only list. As you are using gmail, sending text only messages is very easy, and may clear confusion in future posts. HTH, Jon On Thu, Jun 2, 2011 at 11:23 AM, Jim Silverton jim.silver...@gmail.com

Re: [R] Removing rows of zeros from a matrix

2011-06-02 Thread Petr Savicky
On Thu, Jun 02, 2011 at 11:23:28AM -0400, Jim Silverton wrote: Hi, Can someone tell me how to remove rows of zeros from a matrix? For example if I have the following matrix, 0 0 0 1 2 8 0 0 4 56 I should end up with 0 1 2 8 4 56 Hi. Try the following a - matrix(c(0, 0, 2, 0,

Re: [R] Removing rows with earlier dates

2010-12-29 Thread Ali Salekfard
Thanks to everyone. Joshua's response seemed the most concise one, but it used up so much memory that my R just gave error. I checked the other replies and all in all I came up with this, and thought to share it with others and get comments. My structure was as follows: ACCOUNT RULE DATE A1

Re: [R] Removing rows with earlier dates

2010-12-29 Thread Martin Maechler
David Winsemius dwinsem...@comcast.net on Fri, 24 Dec 2010 11:47:05 -0500 writes: On Dec 24, 2010, at 11:04 AM, David Winsemius wrote: On Dec 24, 2010, at 8:45 AM, Ali Salekfard wrote: Hi all, I'm new to the list but have benfited from it quite

Re: [R] Removing rows with earlier dates

2010-12-29 Thread David Winsemius
On Dec 29, 2010, at 9:24 AM, Ali Salekfard wrote: Thanks to everyone. Joshua's response seemed the most concise one, but it used up so much memory that my R just gave error. I checked the other replies and all in all I came up with this, and thought to share it with others and get

Re: [R] Removing rows with earlier dates

2010-12-29 Thread David Winsemius
On Dec 29, 2010, at 11:03 AM, Ali Salekfard wrote: David, Thanks alot. Your code is worked fine on the whole dataset (no memory error as I had with the other ideas). I do like the style - especialy the fact that it is all in one line - , but for large datasets it takes longer than

Re: [R] Removing rows with earlier dates

2010-12-29 Thread Ali Salekfard
David, Thanks alot. Your code is worked fine on the whole dataset (no memory error as I had with the other ideas). I do like the style - especialy the fact that it is all in one line - , but for large datasets it takes longer than what I wrote. I ran it on the same machine with the same set of

Re: [R] Removing rows with earlier dates

2010-12-29 Thread William Dunlap
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ali Salekfard Sent: Wednesday, December 29, 2010 6:25 AM To: r-help@r-project.org Subject: Re: [R] Removing rows with earlier dates Thanks to everyone. Joshua's response

[R] Removing rows with earlier dates

2010-12-24 Thread Ali Salekfard
Hi all, I'm new to the list but have benfited from it quite extensively. Straight to my rather strange question: I have a data frame that contains mapping rules in this way: ACCOUNT, RULE COLUMNS, Effective Date The dataframe comes from a database that stores all dates. What I would like to

Re: [R] Removing rows with earlier dates

2010-12-24 Thread David Winsemius
On Dec 24, 2010, at 8:45 AM, Ali Salekfard wrote: Hi all, I'm new to the list but have benfited from it quite extensively. Straight to my rather strange question: I have a data frame that contains mapping rules in this way: ACCOUNT, RULE COLUMNS, Effective Date The dataframe comes from

Re: [R] Removing rows with earlier dates

2010-12-24 Thread David Winsemius
On Dec 24, 2010, at 11:04 AM, David Winsemius wrote: On Dec 24, 2010, at 8:45 AM, Ali Salekfard wrote: Hi all, I'm new to the list but have benfited from it quite extensively. Straight to my rather strange question: I have a data frame that contains mapping rules in this way: ACCOUNT,

Re: [R] Removing rows with earlier dates

2010-12-24 Thread Joshua Wiley
Hi, On Fri, Dec 24, 2010 at 5:45 AM, Ali Salekfard salekf...@googlemail.com wrote: [snip] I have a data frame that contains mapping rules in this way: ACCOUNT, RULE COLUMNS, Effective Date The dataframe comes from a database that stores all dates. What I would like to do is to create a

Re: [R] Removing rows with earlier dates

2010-12-24 Thread William Dunlap
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ali Salekfard Sent: Friday, December 24, 2010 5:46 AM To: r-help@r-project.org Subject: [R] Removing rows with earlier dates Hi all, I'm new to the list but have benfited

Re: [R] Removing rows with earlier dates

2010-12-24 Thread Joshua Wiley
with(YourDataFrame, tapply(`Effective Date`, `RULE COLUMNS`,  function(x) x[which.max(x)])) David pointed out that this will just return a table of dates. One work around is: do.call(rbind, by(DataFrame, DataFrame[, RULE COLUMNS], function(x) x[which.max(x[, Effective Date]), ])) but that

Re: [R] Removing rows with earlier dates

2010-12-24 Thread Greg Snow
Whenever a task calls for breaking a data object into pieces, operate on the pieces, then put it back together, then think about using the plyr package. Sent from my iPod On Dec 24, 2010, at 6:58 AM, Ali Salekfard salekf...@googlemail.com wrote: Hi all, I'm new to the list but have

Re: [R] removing rows from a matrix using condition within groups

2010-10-21 Thread swam
I tired this and seems to capture only a few -- View this message in context: http://r.789695.n4.nabble.com/removing-rows-from-a-matrix-using-condition-within-groups-tp3004132p3005894.html Sent from the R help mailing list archive at Nabble.com. __

Re: [R] removing rows from a matrix using condition within groups

2010-10-21 Thread swam
thanks Henrique , it did work with a slight modif subset(merge(X, Y, by.x = 'groups', by.y = 1, all = TRUE), var2var3). -- View this message in context: http://r.789695.n4.nabble.com/removing-rows-from-a-matrix-using-condition-within-groups-tp3004132p3005899.html Sent from the R help mailing

[R] removing rows from a matrix using condition within groups

2010-10-20 Thread swam
I am needing some help in removing certain rows in a data.matrix and then do some calculation. So Iam need to removing certain values above a threshold or value from another vector. For eg.. in the below data matrix X there are 6 groups (A, B, C, D, E ,F) X rowsgroups values 1 A

Re: [R] removing rows from a matrix using condition within groups

2010-10-20 Thread Henrique Dallazuanna
Try this: subset(merge(X, Y, by.x = 'groups', by.y = 1, all = TRUE), values V2, -V2) On Wed, Oct 20, 2010 at 1:37 PM, swam sundars...@yahoo.com wrote: I am needing some help in removing certain rows in a data.matrix and then do some calculation. So Iam need to removing certain values

[R] removing rows with NAs in anywere

2009-12-22 Thread milton ruser
Dear all, I have a data.frame with some NAs that can happens anywere, and I would like to keep only rows without NAs. Thanks in advance for your help, and Merry Xmas. myvect-runif(100) myvect[sample(1:100)[1:5]]-NA myDF-data.frame(matrix(myvect,ncol=5)) myDF miltinho [[alternative HTML

Re: [R] removing rows with NAs in anywere

2009-12-22 Thread Dimitris Rizopoulos
try this: myDF[complete.cases(myDF), ] Best, Dimitris milton ruser wrote: Dear all, I have a data.frame with some NAs that can happens anywere, and I would like to keep only rows without NAs. Thanks in advance for your help, and Merry Xmas. myvect-runif(100) myvect[sample(1:100)[1:5]]-NA

[R] Removing rows

2009-03-12 Thread Tammy Ma
Hi All, act_2 DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 55 2006-02-22 14:52:49 14 52 49 4 57 2006-02-22 14:52:51 14 52 51

[R] Removing rows with rowsums==0 (I can't figure this out)

2008-11-20 Thread stephen sefick
##I want to remove the rows where the row sums are zero and this is as far as I have gotten ffg - (structure(list(CD = c(0, 0, 0, 0, 3.125, 0, 0, 0, 0, 1.6, 3.125, 0, 0, 6.25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.125, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.6, 0, 0, 0, 0, 0, 0, 0, 0,

Re: [R] Removing rows with rowsums==0 (I can't figure this out)

2008-11-20 Thread Gavin Simpson
On Thu, 2008-11-20 at 12:01 -0500, stephen sefick wrote: ##I want to remove the rows where the row sums are zero and this is as far as I have gotten Given your ffg, ## the which() call returns row indices for rows with rowSum 0 ffg[which(rowSums(ffg) 0, ] does the trick HTH G ffg -

Re: [R] Removing rows with rowsums==0 (I can't figure this out)

2008-11-20 Thread Gavin Simpson
On Thu, 2008-11-20 at 17:08 +, Gavin Simpson wrote: On Thu, 2008-11-20 at 12:01 -0500, stephen sefick wrote: ##I want to remove the rows where the row sums are zero and this is as far as I have gotten Given your ffg, ## the which() call returns row indices for rows with rowSum 0

Re: [R] Removing rows with rowsums==0 (I can't figure this out)

2008-11-20 Thread Sarah Goslee
On Thu, Nov 20, 2008 at 12:28 PM, Gavin Simpson [EMAIL PROTECTED] wrote: But Prof. Ripley has pointed out (off list) that ffg[rowSums(ffg) 0, ] I suggested much the same solution off-list (using apply rather than rowSums, as I'm apparently incapable of remembering the existence of the

[R] Removing rows from a data frame

2008-06-30 Thread Joe Trubisz
Hi... I have a rather large dataframe that I'm trying to remove rows from. I'm issuing the command: dtx[-which(dtx$rdate 2008-06-16),] and it tries to print out over 170,000 lines of output. So...I did: options(max.print=1e6) and ran it again. It worked, but when I did a: which(dtx$rdate

Re: [R] Removing rows from a data frame

2008-06-30 Thread Erik Iverson
R is doing what you are telling it to do. You aren't assigning the result of your indexing to a new data.frame, and so it is simply print()ing the result. Example, x - 1:10 x[-1] x vs. x - 1:10 x - x[-1] x Joe Trubisz wrote: Hi... I have a rather large dataframe that I'm trying to

[R] removing rows from matrix

2008-05-02 Thread Monna Nygård
Hi, I have a problem regarding matrix handeling. I am working with a serie of matrixes containing several columns. Now I would like to delete those rows of the matrixes,that in one of the columns contain values less than 50 or greater than 1000. How would this be possible, I have tried to

Re: [R] removing rows from matrix

2008-05-02 Thread Richard . Cotton
Hi, I have a problem regarding matrix handeling. I am working with a serie of matrixes containing several columns. Now I would like to delete those rows of the matrixes,that in one of the columns contain values less than 50 or greater than 1000. Try this: m - matrix(runif(150, 0, 1050),