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
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[,
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(
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
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:
>>>
>>
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
> -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
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
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
>
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
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
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
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,
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
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
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
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
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
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
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
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
?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
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
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
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
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
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
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
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
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...
>
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
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
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
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.
__
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:
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
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.
_
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
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
# 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
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
# 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
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,]
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
44 matches
Mail list logo