Re: [R] delete rows with duplicate numbers of opposite signs in the same column

2013-11-15 Thread arun
Hi, Try: library(plyr)  fun1 <- function(dat){  fun2 <- function(x) {indx <- x <0   x1 <- x[!indx] %in% abs(x[indx])   x2 <- abs(x[indx]) %in% x[!indx]   x3 <- rbind(x[!indx][x1],x[indx][x2])   x[!x %in% x3]}  if(length(colnames(dat)) > 2) {   lapply(colnames(dat)[-1], function(x) {   dat1 <- cbi

Re: [R] Delete rows from dataset

2012-06-06 Thread Rui Barradas
Hello, Try fun <- function(x){ one <- which(x$score == 1) # rows to remove if(length(one) == 1) x else if(length(one) > 1) x[-one[-sample(seq_along(one), 1)], ] # all but a randomly sampled row } res <- lapply(split(data.frame(dat), dat[,

Re: [R] Delete rows from data.frame matching a certain criteria

2012-03-02 Thread Petr PIKAL
Hi my favourite would be test$v[which(test$pattern==1)]<-NA Regards Petr > Hi, > > On Mar 1, 2012, at 12:38 PM, Sarah Goslee wrote: > > > Hi, > > > > On Thu, Mar 1, 2012 at 11:11 AM, mails wrote: > >> Hello, > >> > >> > >> consider the following data.frame: > >> > >> test <- data.frame(

Re: [R] Delete rows from data.frame matching a certain criteria

2012-03-01 Thread David Winsemius
On Mar 1, 2012, at 1:02 PM, Sarah Goslee wrote: You're all correct: I copied in the wrong thing. My apologies! On Thu, Mar 1, 2012 at 1:00 PM, Ista Zahn wrote: Hi, On Mar 1, 2012, at 12:38 PM, Sarah Goslee wrote: Hi, On Thu, Mar 1, 2012 at 11:11 AM, mails wrote: Hello, consider the f

Re: [R] Delete rows from data.frame matching a certain criteria

2012-03-01 Thread Sarah Goslee
You're all correct: I copied in the wrong thing. My apologies! On Thu, Mar 1, 2012 at 1:00 PM, Ista Zahn wrote: > Hi, > > On Mar 1, 2012, at 12:38 PM, Sarah Goslee wrote: > >> Hi, >> >> On Thu, Mar 1, 2012 at 11:11 AM, mails wrote: >>> Hello, >>> >>> >>> consider the following data.frame: >>> >>

Re: [R] Delete rows from data.frame matching a certain criteria

2012-03-01 Thread Ista Zahn
Hi, On Mar 1, 2012, at 12:38 PM, Sarah Goslee wrote: > Hi, > > On Thu, Mar 1, 2012 at 11:11 AM, mails wrote: >> Hello, >> >> >> consider the following data.frame: >> >> test <- data.frame(n = c(1,2,3,4,5), v = c(6,5,7,5,3), pattern = >> c(1,1,NA,1,NA)) >> < snip > >> So basically the resu

Re: [R] Delete rows from data.frame matching a certain criteria

2012-03-01 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of mails > Sent: Thursday, March 01, 2012 8:11 AM > To: r-help@r-project.org > Subject: [R] Delete rows from data.frame matching a certain criteria > > Hel

Re: [R] Delete rows from data.frame matching a certain criteria

2012-03-01 Thread jim holtman
Your criteria did not make sense since in both cases pattern == 1, so I chose to set to NA if pattern == 1 > test <- data.frame(n = c(1,2,3,4,5), v = c(6,5,7,5,3), pattern = + c(1,1,NA,1,NA)) > test n v pattern 1 1 6 1 2 2 5 1 3 3 7 NA 4 4 5 1 5 5 3 NA > # set v to NA

Re: [R] Delete rows from data.frame matching a certain criteria

2012-03-01 Thread Sarah Goslee
Hi, On Thu, Mar 1, 2012 at 11:11 AM, mails wrote: > Hello, > > > consider the following data.frame: > > test <- data.frame(n = c(1,2,3,4,5), v = c(6,5,7,5,3), pattern = > c(1,1,NA,1,NA)) > >> test >  n v pattern > 1  1     6       1 > 2  2     5       1 > 3  3     7      NA > 4  4     5       1 >

[R] Delete rows from data.frame matching a certain criteria

2012-03-01 Thread mails
Hello, consider the following data.frame: test <- data.frame(n = c(1,2,3,4,5), v = c(6,5,7,5,3), pattern = c(1,1,NA,1,NA)) > test n v pattern 1 1 6 1 2 2 5 1 3 3 7 NA 4 4 5 1 5 5 3 NA I tried to use apply and the adply function to set v t

Re: [R] Delete Rows Dynamically Within a Loop

2011-11-19 Thread Uwe Ligges
1. Perhaps it is easier to explain what the result should be than explaining your algorithm. There may be an easier approach to it. 2. Your code is not reproducible for us, since we do not have the full data nor disc, radius, . Uwe Ligges On 18.11.2011 02:20, ftonini wrote: Ok guys, a

[R] Delete Rows Dynamically Within a Loop

2011-11-17 Thread ftonini
Ok guys, as requested, I will add more info so that you understand why a simple vector operation is not possible. It's not easy to explain in few words but let's see. I have a huge amount of points over a 2D space. I divide my space in a grid with a given resolution,say, 100m. The main loop that I

Re: [R] delete rows whose sum is X

2011-03-04 Thread Uwe Ligges
On 04.03.2011 15:52, Ivan Calandra wrote: True, I didn't think about it because the matrix is supposed to be filled with 0 and 1, and I automatically thought about integers. It wouldn't be a problem with integers, right? If the matrix is really an integer matrix, right, otherwise not. Best,

Re: [R] delete rows whose sum is X

2011-03-04 Thread Ivan Calandra
True, I didn't think about it because the matrix is supposed to be filled with 0 and 1, and I automatically thought about integers. It wouldn't be a problem with integers, right? Le 3/4/2011 15:47, Uwe Ligges a écrit : On 04.03.2011 15:41, Ivan Calandra wrote: Oops, forgot one "=": mat[appl

Re: [R] delete rows whose sum is X

2011-03-04 Thread Uwe Ligges
On 04.03.2011 15:41, Ivan Calandra wrote: Oops, forgot one "=": mat[apply(mat, 1, FUN=function(x) sum(x)==5),] Yes, but since floating point issues may ba apparent in the end, I'd vote for: mat[apply(mat, 1, FUN = function(x) isTRUE(all.equal(sum(x), 5))),] Le 3/4/2011 15:36, Ivan Cal

Re: [R] delete rows whose sum is X

2011-03-04 Thread Ivan Calandra
Oops, forgot one "=": mat[apply(mat, 1, FUN=function(x) sum(x)==5),] Le 3/4/2011 15:36, Ivan Calandra a écrit : Hi Mikael You really need to provide a reproducible example in the future, it will help people to better understand what you want to do and help you, and help you better understand

Re: [R] delete rows whose sum is X

2011-03-04 Thread Ivan Calandra
Hi Mikael You really need to provide a reproducible example in the future, it will help people to better understand what you want to do and help you, and help you better understand the answers as well. Try something like this: mat[apply(mat, 1, FUN=function(x) sum(x)=5),] HTH, Ivan Le 3/4/2

Re: [R] delete rows whose sum is X

2011-03-04 Thread Sarah Goslee
On Fri, Mar 4, 2011 at 8:50 AM, purna wrote: > Rnoob here. > I have a matrix of zeroes ond ones. I want to delete the rows whose sum of > values is not =5, alternatively extract the rows who sum up to 5. > > Thank you/Mikael I think you would greatly benefit from reading some of the intro to R ma

[R] delete rows whose sum is X

2011-03-04 Thread purna
Rnoob here. I have a matrix of zeroes ond ones. I want to delete the rows whose sum of values is not =5, alternatively extract the rows who sum up to 5. Thank you/Mikael -- View this message in context: http://r.789695.n4.nabble.com/delete-rows-whose-sum-is-X-tp3335254p3335254.html Sent from th

Re: [R] delete rows

2011-02-07 Thread Robert Baer
ter" Sent: Sunday, February 06, 2011 8:16 PM To: Subject: [R] delete rows Hello. I came across your response in an R forum and could use your help. I have a data set with 472 rows. I want to delete rows 416 through 472. The name of my data set is MERGE. I am an extreme R novice. How do I wr

Re: [R] delete rows

2011-02-06 Thread Bert Gunter
On Sun, Feb 6, 2011 at 6:16 PM, Christopher Porter wrote: > Hello. I came across your response in an R forum and could use your help. I > have a data set with 472 rows. I want to delete rows 416 through 472. The > name of my data set is MERGE. > > I am an extreme R novice. How do I write a script

Re: [R] delete rows

2011-02-06 Thread Santosh Srinivas
?subset On Mon, Feb 7, 2011 at 7:46 AM, Christopher Porter wrote: > Hello. I came across your response in an R forum and could use your help. I > have a data set with 472 rows. I want to delete rows 416 through 472. The > name of my data set is MERGE. > > I am an extreme R novice. How do I writ

Re: [R] delete rows

2011-02-06 Thread Joshua Wiley
Hi, On Sun, Feb 6, 2011 at 6:16 PM, Christopher Porter wrote: > Hello. I came across your response in an R forum and could use your help. I > have a data set with 472 rows. I want to delete rows 416 through 472. The > name of my data set is MERGE. Try this: MERGE2 <- MERGE[-c(416:472), ] Che

[R] delete rows

2011-02-06 Thread Christopher Porter
Hello. I came across your response in an R forum and could use your help. I have a data set with 472 rows. I want to delete rows 416 through 472. The name of my data set is MERGE. I am an extreme R novice. How do I write a script to accomplish this? Thank you. --- Christopher H. Porter, M.A

Re: [R] Delete rows in the data frame by limiting values in two columns

2010-06-25 Thread Erik Iverson
x=c('germany','poor italy','usa','england','poor italy','japan') y=c('Spain','germany','usa','brazil','england','chile') s=1:6 z=3:8 test=data.frame(x,y,s,z) #Now I only concern the countries ('germany','england','brazil'). I would like to keep the rows where these three countries #are involved

Re: [R] Delete rows in the data frame by limiting values in two columns

2010-06-25 Thread Henrique Dallazuanna
Try this: test[rowSums(mapply('%in%', test[c('x', 'y')], list(c('germany','england','brazil' > 0,] On Fri, Jun 25, 2010 at 4:00 PM, Yi wrote: > Hi, folks, > > Finally Friday~~ Here comes the question: > > x=c('germany','poor italy','usa','england','poor italy','japan') > y=c('Spain','german

[R] Delete rows in the data frame by limiting values in two columns

2010-06-25 Thread Yi
Hi, folks, Finally Friday~~ Here comes the question: x=c('germany','poor italy','usa','england','poor italy','japan') y=c('Spain','germany','usa','brazil','england','chile') s=1:6 z=3:8 test=data.frame(x,y,s,z) #Now I only concern the countries ('germany','england','brazil'). I would like to ke

Re: [R] Delete rows with duplicate field...

2010-05-04 Thread kMan
Dear someone, Jorge's solution is excellent, assuming it is what you had in mind. Please note that the help page for unique() has duplicated() listed in its "See Also" section. Thus, when you studied ?unique(), it would have made sense to read about duplicated() as well. Or perhaps you did look in

Re: [R] Delete rows with duplicate field...

2010-05-03 Thread David Winsemius
On May 3, 2010, at 9:59 AM, someone wrote: I dont want to apply the unique for all columns but just the ID column. dataset[ !duplicated(dataset$ID), ] -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://s

Re: [R] Delete rows with duplicate field...

2010-05-03 Thread Jorge Ivan Velez
How about yourdata[ !duplicated(yourdata$ID), ] ? See ?duplicated for more information. HTH, Jorge On Mon, May 3, 2010 at 9:04 AM, someone <> wrote: > > as a r noob i am having another problem: > i have a big dataframe where each row corresponds to one entry and each > column is a field... >

Re: [R] Delete rows with duplicate field...

2010-05-03 Thread Dennis Murphy
Hi: Here are three solutions; since this question comes up fairly often, you can find other solutions in the R-help archives. (1) Use functions from base R: split the data frame by ID, extract the first record from each split and slurp them together with rbind(): > do.call(rbind, lapply(sp

Re: [R] Delete rows with duplicate field...

2010-05-03 Thread someone
could you please elaborate a little more on that? -- View this message in context: http://r.789695.n4.nabble.com/Delete-rows-with-duplicate-field-tp2123939p2124055.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org m

Re: [R] Delete rows with duplicate field...

2010-05-03 Thread Lanna Jin
names() - Lanna Jin lanna...@gmail.com 510-898-8525 -- View this message in context: http://r.789695.n4.nabble.com/Delete-rows-with-duplicate-field-tp2123939p2124036.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-proje

Re: [R] Delete rows with duplicate field...

2010-05-03 Thread someone
I dont want to apply the unique for all columns but just the ID column. -- View this message in context: http://r.789695.n4.nabble.com/Delete-rows-with-duplicate-field-tp2123939p2124011.html Sent from the R help mailing list archive at Nabble.com. __

Re: [R] Delete rows with duplicate field...

2010-05-03 Thread someone
thanks for your effort. to be more precise: ID , OS, time and many more are the columns. each entry is a row. when I do: x <- unique(dataset$ID) It just gives me a list of all IDs (levels). I want to get a dataframe where just one entry (row) for each ID is included... like: userA , Win, 12:

Re: [R] Delete rows with duplicate field...

2010-05-03 Thread Lanna Jin
if that doesn't work, maybe also try: if x is your data frame with length a columns, "unique(x[,1:a])". - Lanna Jin lanna...@gmail.com 510-898-8525 -- View this message in context: http://r.789695.n4.nabble.com/Delete-rows-with-duplicate-field-tp2123939p2123964.html Sent from the R help ma

Re: [R] Delete rows with duplicate field...

2010-05-03 Thread Lanna Jin
Did you try: if x is the data frame, unique(x)? - Lanna Jin lanna...@gmail.com 510-898-8525 -- View this message in context: http://r.789695.n4.nabble.com/Delete-rows-with-duplicate-field-tp2123939p2123956.html Sent from the R help mailing list archive at Nabble.com. _

[R] Delete rows with duplicate field...

2010-05-03 Thread someone
as a r noob i am having another problem: i have a big dataframe where each row corresponds to one entry and each column is a field... for instance, i have the column ID and time and many more... Id like to get a dataframe where all IDs are just included once (some users with that ID might have sev

Re: [R] Delete rows with duplicate field...

2010-05-03 Thread Lanna Jin
Try, unique(dataset[,1:a]), where a is the number of columns that you have. 1:a would apply the unique to all columns. - Lanna Jin lanna...@gmail.com 510-898-8525 -- View this message in context: http://r.789695.n4.nabble.com/Delete-rows-with-duplicate-field-tp2123939p2123976.html Sent fr

Re: [R] Delete rows from matrix having at least one zero value

2008-11-09 Thread stephen sefick
# I think this does what you want d <- rbind(c(1,0,6,4), c(2,5, 7,5), c(3,6,8,6), c(4,0,0,0)) f <- as.matrix(d) f[-which(rowSums(f==0)>0),] On Sun, Nov 9, 2008 at 8:30 AM, mentor_ <[EMAIL PROTECTED]> wrote: > > Have found a solution: > > matrix[rowSums

Re: [R] Delete rows from matrix having at least one zero value

2008-11-09 Thread Jorge Ivan Velez
Dear mentor_, Try also yourmat <- matrix(c( 1,0,6,4, 2,5, 7,5, 3,6,8,6, 4,0,0,0 ),ncol=4,byrow=TRUE) yourmat[apply(yourmat,1,function(x) sum(x==0)<1),] HTH, Jorge On Sun, Nov 9, 2008 at 7:39 AM, mentor_ <[EMAIL PROTECTED]> wrote: > > Hi, > > I h

Re: [R] Delete rows from matrix having at least one zero value

2008-11-09 Thread stephen sefick
# I think this does what you want d <- rbind(c(1,0,6,4), c(2,5, 7,5), c(3,6,8,6), c(4,0,0,0)) f <- as.matrix(d) f[-which(rowSums(f==0)>0),] On Sun, Nov 9, 2008 at 8:30 AM, mentor_ <[EMAIL PROTECTED]> wrote: > > Have found a solution: > > matrix[rowSums

[R] Delete rows from matrix having at least one zero value

2008-11-09 Thread mentor_
Hi, I have a further question about matrix manipulation. Imagine the following two matrices: > test [,1] [,2] [,3] [,4] [1,]1064 [2,]2575 [3,]3686 [4,]4000 > matrix(is.element(test,0), ncol=4) [,1] [,2] [,3] [,4] [1,]

Re: [R] Delete rows from matrix having at least one zero value

2008-11-09 Thread mentor_
Have found a solution: matrix[rowSums(matrix == 0) == 0, ] mentor_ wrote: > > Hi, > > I have a further question about matrix manipulation. > > Imagine the following two matrices: >> test > [,1] [,2] [,3] [,4] > [1,]1064 > [2,]2575 > [3,]368