In Julia, dataframes are output with a sequential row number. I would like to access the row numbers as if it were a ROWID in the dataframe. I need this to calculate a regression.
Right now I do this with trick to add an extra column (x1) to mimic the rowid:
data = hcat(data, collect(1:size(data,1)));
glm(Column ~ x1, data, Normal(), IdentityLink())
I would like to achieve this directly, without adding an extra x1 column to the table. The x1 column I use now is a workaround. So what I'd like to achieve is to get the first line that adds an extra column. If the x1 column is not added, the glm() function crashes. So I need to find a direct replacement for the x1 in the glm() function (if that is possible).
Is there a simple way to get to the rowid of the tableframe?
Get Number of Rows in DataFrame You can use len(df. index) to find the number of rows in pandas DataFrame, df. index returns RangeIndex(start=0, stop=8, step=1) and use it on len() to get the count.
R provides us nrow() function to get the rows for an object. That is, with nrow() function, we can easily detect and extract the number of rows present in an object that can be matrix, data frame or even a dataset.
We can select rows (observations) by Index in R by using a single square bracket operator df[rows,columns] , From the square bracket, we should be using rows position, and columns are used to select columns. In R rows are called observations and columns are called variables.
Starting from DataFrames v0.22.0 rownumber(dfr::DataFrameRow) returns the row number.
julia> data = DataFrame(a=4:6, b=7:9)
3×2 DataFrame
Row │ a b
│ Int64 Int64
─────┼──────────────
1 │ 4 7
2 │ 5 8
3 │ 6 9
julia> rownumber.(eachrow(data))
3-element Array{Int64,1}:
1
2
3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With