Re: [R] Accessing Data Frame

2019-01-04 Thread Greg Snow
Here is another approach that uses only the default packages: > onecar <- mtcars[10,] > w <- which(duplicated(rbind(mtcars,onecar), fromLast = TRUE)) > w [1] 10 > mtcars.subset <- mtcars[-w,] > > > threecars <- mtcars[c(1,10,15),] > w <- which(duplicated(rbind(mtcars,threecars), fromLast=TRUE)) >

Re: [R] Accessing Data Frame

2019-01-03 Thread Bert Gunter
I do not know how you define "quick way," but as there is an "==" method for data frames (see ?"==" and links therein for details), that allows the straightforward use of basic R functionality: ## using your 'deck' and 'topCard' examples: > deck [ apply(deck == topCard[rep(1,nrow(deck)), ],1, all

Re: [R] Accessing Data Frame

2019-01-03 Thread Jeff Newmiller
AFAIK the intent of the designers of the data frame class was that rownames be unique and be useful for tracking the origins of records in data subsets. However, after a few merging operations the traceability becomes murky anyway and relational set theory avoids them. Neither data.table nor dpl

Re: [R] Accessing Data Frame

2019-01-03 Thread Benoit Galarneau
Many thanks everyone for the rich feedback. Very impressive. I will digest all the information received and continue on my learning around R. Benoit Duncan Murdoch a écrit : On 03/01/2019 12:39 p.m., Benoit Galarneau wrote: Thanks for the feedback. Point taken about the data.table package

Re: [R] Accessing Data Frame

2019-01-03 Thread Duncan Murdoch
On 03/01/2019 12:39 p.m., Benoit Galarneau wrote: Thanks for the feedback. Point taken about the data.table package, I will take a look for sure. As I am new to the R programming, I'm exploring with the default libraries as a start. I have various options that works like this one: topCard <- de

Re: [R] Accessing Data Frame

2019-01-03 Thread Duncan Murdoch
On 03/01/2019 12:39 p.m., Benoit Galarneau wrote: Thanks for the feedback. Point taken about the data.table package, I will take a look for sure. As I am new to the R programming, I'm exploring with the default libraries as a start. I have various options that works like this one: topCard <- de

Re: [R] Accessing Data Frame

2019-01-03 Thread Berry, Charles
See below. > On Jan 3, 2019, at 6:50 AM, Benoit Galarneau > wrote: > > Hi everyone, > I'm new to the R world. > Probably a newbie question but I am stuck with some concept with data frame. > I am following some examples in the "Hands-On Programming with R". > > In short, how can I access/filte

Re: [R] Accessing Data Frame

2019-01-03 Thread Benoit Galarneau
Thanks for the feedback. Point taken about the data.table package, I will take a look for sure. As I am new to the R programming, I'm exploring with the default libraries as a start. I have various options that works like this one: topCard <- deck[1,] #Remove card from deck using row name d

Re: [R] Accessing Data Frame

2019-01-03 Thread Jeff Newmiller
You would be better served to reference SQL semantics (relational identity) than Network database semantics (object identifiers) for understanding data frames. The row in `aCard` is not the same as the row in `deck`, and you should not construct your algorithms based on individual rows but rathe

Re: [R] Accessing Data Frame

2019-01-03 Thread Jeff Newmiller
>In my programmer's head, something similar to this should "work": ... > deck[aCard] There are some people who agree with you... see the data.table package, which can be made to behave like this. Keep in mind that the aCard data frame in general may have a different set of column names or more

Re: [R] Accessing Data Frame

2019-01-03 Thread Benoit Galarneau
You are correct, the anti_join is working fine. However, I still find it strange there is no "quick" way to find the index of an item extracted from the data frame. This works as it returns the deck without the card no 10. aCard = deck[10,] cardNo = which(deck$value == aCard$value & deck$suit

Re: [R] Accessing Data Frame

2019-01-03 Thread Ista Zahn
Hi Benoit, You can select rows from deck matched in aCard using merge(deck, aCard) Selecting rows that don't match is bit more difficult. You could do something like isin <- apply(mapply(function(x, y) x %in% y, deck, topCard), 1, all) deck[!isin, ] perhaps. Alte

Re: [R] Accessing Data Frame

2019-01-03 Thread Rui Barradas
Hello, Inline. Às 14:50 de 03/01/2019, Benoit Galarneau escreveu: Hi everyone, I'm new to the R world. Probably a newbie question but I am stuck with some concept with data frame. I am following some examples in the "Hands-On Programming with R". In short, how can I access/filter items in a

[R] Accessing Data Frame

2019-01-03 Thread Benoit Galarneau
Hi everyone, I'm new to the R world. Probably a newbie question but I am stuck with some concept with data frame. I am following some examples in the "Hands-On Programming with R". In short, how can I access/filter items in a data frame using a variable. One example consists of manipulating elem