6 ms·
Does anyone know how dataframe in R compares on these 10/11 points?
by wodenokoto 9y ago
Does anyone know how dataframe in R compares on these 10/11 points?
- huac 9y agoI'd say native data frames in R aren't great at these (maybe #4, maybe #9). I'm excited to see how Arrow can perform, and hopefully we'll see solid bindings to R as well. The data.table package (https://github.com/Rdatatable/data.table/wiki https://github.com/Rdatatable/data.table/wiki) does make progress on some of these - I'd say #1, #3, maybe #7, #8. Dplyr has a query planner too, fwiw.
- sin7 9y agoR data frames have excellent support for missing and categorical data. Everything else is just as much of a problem.
- wesm 9y agoDisagree. Factors (categorical data) in R only support strings
- sin7 9y agoBut they can be ordered and are represented as integers. So you can turn your numerics to factors and keep them in order and do whatever goofy math you want to do on your categorical data.
- wesm 9y agoRight, but I don't think it's fair to say that R's support for categorical data is "excellent" if only strings can be category labels/levels. Categories (aka dictionary-encoded data in other systems) semantically may be any type in practice (strings, timestamps, numbers, etc.). The function as.factor in R is lossy because the input type is coerced to string.
- zzleeper 9y ago> the input type is coerced to string. Wow. Didn't knew that.. strings is the one thing I always minimize in my datasets, due to speed and memory considerations.. BTW, I wanted to thank you for your 2012 slides on how you used hashes to group and join data. It led me to learn more about categoricals and I ended up implementing a Factor() object [1] in the other tool I use (Stata) that ended up being a life saver. In fact, once you have a powerful and fast categorical type, with a set of key functions, you can do anything from group the data, to count distinct categories, to run fixed effect regressions in no time. [1] http://fmwww.bc.edu/repec/scon2017/Baltimore17_Correia.pdf http://fmwww.bc.edu/repec/scon2017/Baltimore17_Correia.pdf
- rcthompson 9y agoMemory isn't the issue. Both factors and string vectors only store each unique string once in memory. The issue is the limitation that factor levels can only be strings and not any other data type. Also, I think testing strings for equality is O(1) since it should simplify to a pointer comparison.
- stewbrew 9y agoThat's not right. Factor _levels_ can only be integers, factor _labels_ can only be strings since labels are the printable representation of a level. Maybe you could store the "real" values of a level as attribute (I.e. metadata) of the factor. Anyway, I think that's as solvable problem.
- rcthompson 9y agoWell, I don't know if there's a standard terminology used elsewhere, but what you call labels, R calls levels.
- stewbrew 9y agoErm ... Well, I admit it's somewhat confusing. factor(x = character(), levels, labels = levels, exclude = NA, ordered = is.ordered(x), nmax = NA) [...] levels : an optional vector of the values (as character strings) that x might have taken. The default is the unique set of values taken by as.character(x), sorted into increasing order of x. Note that this set can be specified as smaller than sort(unique(x)). labels : either an optional character vector of (unique) labels for the levels (in the same order as levels after removing those in exclude), or a character string of length 1. This way, you can do something like that: > x <- 1:3 > factor(x, levels = 1:2, labels = c("foo", "bar")) [1] foo bar <NA> Levels: foo bar But this actually is: > factor(as.character(x), levels = c("1", "2"), labels = c("foo", "bar")) [1] foo bar <NA> Levels: foo bar
- olympus 9y agoI'm not an R-guru, but I did my thesis with 5k lines of R, so I'd call myself proficent: Point 10: R has lazy evaluation, which means here that a function will not be evaluated when you define it, it will be evaluated when you call it (maybe not quite the same as some other language's lazy eval). I'm not aware of any built in feature for query planning, if you ask for nrow(some_func(myframe)), it will evaluate the some_func(myframe) function and then count up the rows. You could always write your own query planning function I suppose. Point 11: R has several multicore/cluster libraries, and some are actually decent. If you are like most R users, you use StackOverflow a lot, and you'll end up with one algorithm that uses the snow package and another algorithm that uses multicore, one that uses parallel, and so on. A few very well written packages have hooks that make going to multiple cores easy, but most do not and you typically have to roll your own.
- j2kun 9y ago> R has lazy evaluation, which means here that a function will not be evaluated when you define it, it will be evaluated when you call it. It seems unlikely you meant this as stated. How is it possible to "evaluate a function" when you define it? Certainly you need to give it arguments, and that can only happen when you call it.
- deleted 9y ago[deleted]
- olympus 9y agoA clearer explanation is the lazy evaluation here: http://adv-r.had.co.nz/Functions.html#function-arguments http://adv-r.had.co.nz/Functions.html#function-arguments I can pass an argument but R won’t try to evaluate unless it needs it. This can be beneficial when only some of a function’s branches need the argument. You can pass a solver for the traveling salesman problem but R won’t waste CPU cycles until it reaches a point where it has to solve the TSP to get an answer. Maybe the first branch of the function is a feasibility check, and the TSP will be skipped for something else. This is a little harder to explain for data frames, but you can create R functions that act a little like generators in python. This can help with memory management where instead of a gigantic matrix you have a function that generates the part of the matrix that you need.