go-gota / gota

Gota: DataFrames and data wrangling in Go (Golang)
Other
3.04k stars 281 forks source link

The example doesn't add up. #30

Closed typeless closed 6 years ago

typeless commented 7 years ago

The function application example in the README:

mean := func(s series.Series) series.Series {
    floats := s.Float()
    sum := 0.0
    for _, f := range floats {
        sum += f
    }
    return series.Floats(sum / float64(len(floats)))
}
df.Cbind(mean)
df.Rbind(mean)

CBind and RBind seem to receive a DataFrame value rather than a function value. (?)

kniren commented 7 years ago

You are right, that is a typo, it should be df.Capply(mean) and df.Rapply(mean), you can check the docs here:

https://godoc.org/github.com/kniren/gota/dataframe

typeless commented 7 years ago

I don't quite understand how Rapply works despite having read the documentation and looked into the code. Are the elements of the row processed by Rapply necessarily the same type?

kniren commented 7 years ago

When creating a series.Series for a given type all the elements will be converted to said type. In case of Rapply each row is first casted to the appropriate type with priority: String -> Float -> Int -> Bool. What this means is that if you have a column of type String and the rest of the columns are of type Int, the row will be casted to a String type. This casted row is then passed to the function to apply.

kniren commented 6 years ago

Fixed on #40