Live data from Hacker News

An opinionated view of the Tidyverse “dialect” of the R language

github.com

151–156 of 156 posts

Re: An opinionated view of the Tidyverse “dialect” of the R language

#151
post #140

Earlier quoted context omitted.

I use a simply device to keep these straight: - (l)apply: List apply always returns a list - (s)apply: simplify apply tries to return simplified result - (v)apply: verify apply checks the return type conforms to user supplied example - (m)apply: multiple apply applies FUN to multiple vectors - (r)apply: recursive apply is essentially a flatmap - apply : no device here, only use on matrices, never data.frames

After reading your explanation I still, as has been the case for years, don't understand what sapply or rapply does, and vapply sounds weird. That isn't going to change, because I'm just not going to use them or 'invest' the time in finding out what some statistician-of-yore's interpretation of a map is. Instead I'll stick to tidyverse map - returns a list. Or tidyverse map_[int/chr/dbl/etc, etc] if I want a vector o…

> After reading your explanation I still, as has been the case for years, don't understand what sapply or rapply does,

There is nothing complicated about what sapply does... It simply means loop over the elements of the first argument (which must be a list; btw a dataframe, df, is internally the same as a list) and apply some function. lapply does this and returns a list, sapply does this and can optionally "simplify" the results into a vector, etc.

So:

lapply(df, class) = loop over the elements of df and tell me the class, return this in the form of a list

sapply(df, class) = loop over the elements of df and tell me the class, return this as a character vector

This is basically lapply:

  res = NULL
  for(i in 1:length(df)){
  res = append(res, class(df[i]))
  }
  return(res)

Re: An opinionated view of the Tidyverse “dialect” of the R language

#152
post #63

> Ironically, though consistency of interface is a goal, new versions of Tidy libraries are often incompatible with older ones, a very serious problem in the software engineering world. I was (sadly) amused by a recent comment on HN linking to some tweets celebrating that some R code still ran four years later.

That was my comment, and the point wasn't that the R code still ran four years later--the point was that R Core's focus on backwards compatibility (in reference to R being hamstrung via its focus on "compatibility with S") isn't a bad thing. You're never going to get the 2.x - 3.x schism that python had with future version of R, assuming R core continues with that philosophy.

Re: An opinionated view of the Tidyverse “dialect” of the R language

#153
post #63

> Ironically, though consistency of interface is a goal, new versions of Tidy libraries are often incompatible with older ones, a very serious problem in the software engineering world. I was (sadly) amused by a recent comment on HN linking to some tweets celebrating that some R code still ran four years later.

That was my comment, and the point wasn't that the R code still ran four years later--the point was that R Core's focus on backwards compatibility (in reference to R being hamstrung via its focus on "compatibility with S") isn't a bad thing. You're never going to get the 2.x - 3.x schism that python had with future version of R, assuming R core continues with that philosophy.

[deleted]

Re: An opinionated view of the Tidyverse “dialect” of the R language

#154
post #63

> Ironically, though consistency of interface is a goal, new versions of Tidy libraries are often incompatible with older ones, a very serious problem in the software engineering world. I was (sadly) amused by a recent comment on HN linking to some tweets celebrating that some R code still ran four years later.

That was my comment, and the point wasn't that the R code still ran four years later--the point was that R Core's focus on backwards compatibility (in reference to R being hamstrung via its focus on "compatibility with S") isn't a bad thing. You're never going to get the 2.x - 3.x schism that python had with future version of R, assuming R core continues with that philosophy.

I completely agree with your point and I think saying that R is keeping compatibility with S doesn’t make much sense. R is keeping compatibility with R, as it should.

Maybe I lack context, but those tweets looked to me as if someone said “I can run this four year old game in the latest release of Windows!” or “Three versions of Office later I can still open my excel files!”

Re: An opinionated view of the Tidyverse “dialect” of the R language

#155
post #103

Earlier quoted context omitted.

With regards to the usefulness of piping with dplyr: the post does express its admiration for data.table as the alternative for dplyr. In data.table, chaining operations together is standard and as simple as a set of brackets to contain the next operation. Both are preferable to pandas though (joke not troll).

There are nuances that to me make R data frames, especially with Magrittr, simpler to work with over Pandas. Pandas indexing always seems to get in the way. I have been using Python a lot longer than R, but the Pandas syntax is taking longer to internalize. Maybe it's just me?

For those R users who aren't quite enjoying Pandas so much, I enjoyed the following blog post: https://stmorse.github.io/journal/tidyverse-style-pandas.htm...

Re: An opinionated view of the Tidyverse “dialect” of the R language

#156

Earlier quoted context omitted.

I run a large scale national survey. We download the data from our survey platform. Survey respondents are asked 100+ questions. The questions change week to week and so the column names are not consistent. We exclude respondents who appear to be cheating the system (rushing through questions, straight-lining, skipping almost every question, etc.) As part of our completion check, we want to do a row-wise map of the d…

You are right that tidy data is in a different form that many supplied tables are. If I understand correctly, you want to know how many NA's there are in each column in a wide-form dataset (as opposed to a tidy dataset) # One line to make the data tidy. # The form of data will be 3 columns: id, question, answer, and no, we don't care what the columns are called, except for id. tidydf % gather("question", "answer", -i…

I agree that an alternative way to do this would be to mutate an ID column (maybe row number), then gather, then summarize, except that this of course will throw away all the rest of the data, so not great if all you want to do is add a column. Hence, I normally map rows or use base R.
Post reply on HN