R-table in Julia (for DataFrames)

Is there something like table R function in Julia? I read about xtab but don't know how to use it.

Suppose R is data.frame rdata , which col6 is of type Factor .

R code example:

rdata <- read.csv("mycsv.csv") #1 table(rdata$col6) #2

To read data and create factors in Julia, I do it like this:

using DataFrames jldata = readtable("mycsv.csv", makefactors=true) #1 :col6 will be now pooled.

... but how to build table R, as in julia (how to reach # 2)?

+5
source share
2 answers

You can use the countmap function from StatsBase.jl to count the entries of a single variable. There are currently no common crosstabs and statistical tests for contingency tables. As Ismail points out, this was discussed in the problem tracker for StatsBase.jl .

+4
source

I came to the conclusion that a similar effect can be achieved with by :

Let jldata consist of a column :gender .

julia> by(jldata, :gender, nrow) 3x2 DataFrames.DataFrame | Row | gender | x1 | |-----|----------|-------| | 1 | NA | 175 | | 2 | "female" | 40254 | | 3 | "male" | 58574 |

Of course, this is not a table , but at least I get the same data type as the data source. Surprisingly, by seems faster than countmap .

+4
source

Source: https://habr.com/ru/post/1240085/


All Articles