xuyiqing / tjbal

Trajectory Balancing
MIT License
11 stars 10 forks source link

Index variable error caused by data table #10

Open pchest opened 1 year ago

pchest commented 1 year ago

If the input data for the tjbal function is in the data.table format, then the will raise the following error, even if all index variables are in the numeric format:

The time indicator must be numeric

This error is caused by line 180 in the R/tjbal.R file:

if(is.numeric(data[,time])==FALSE) {
    stop("The time indicator must be numeric.")
    }

Data table objects treat variables input into the column dimension as literal variable names in the data table itself, not as local variables from your function. This issue can be addressed by converting data table objects to data frames using the as.data.frame function.

xuyiqing commented 1 year ago

Dear Patrick,

Thank you! Could you send a minimally reproducible example to @.***?

Best, Yiqing

On Tue, Jul 18, 2023 at 1:50 PM Patrick Chester @.***> wrote:

If the input data for the tjbal function is in the data.table format, then the will raise the following error, even if all index variables are in the numeric format:

The time indicator must be numeric

This error is caused by line 180 in the R/tjbal.R file:

if(is.numeric(data[,time])==FALSE) { stop("The time indicator must be numeric.") }

Data table objects treat variables input into the column dimension as literal variable names in the data table itself, not as variables local variables in your function. This issue can be addressed by converting data table objects to data frames using the as.data.frame function.

— Reply to this email directly, view it on GitHub https://github.com/xuyiqing/tjbal/issues/10, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2PKGBM6TRIW5PBLIBLSZLXQ3ZJBANCNFSM6AAAAAA2O55QII . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- Yiqing Xu

Assistant Professor Department of Political Science Stanford University https://yiqingxu.org/

pchest commented 1 year ago

Hi Yiqing,

No problem! Actually, it appears as though I was mistaken in my original post. The error is not caused by data.table, but by adding dplyr groups to a tibble. The proposed solution -- converting the grouped data frame to a regular data frame -- still works though.

For some reason, I can't see the email address you listed above, but I can send the replication code to your Gmail email address if that's alright. Please let me know if you've received it!

Best, Patrick

xuyiqing commented 1 year ago

I got it, thanks! Let me know if you keep getting issues.

On Tue, Jul 18, 2023 at 4:43 PM Patrick Chester @.***> wrote:

Hi Yiqing,

No problem! Actually, it appears as though I was mistaken in my original post. The error is not caused by data.table, but by adding dplyr groups to a tibble. The proposed solution -- converting the grouped data frame to a regular data frame -- still works though.

For some reason, I can't see the email address you listed above, but I can send the replication code to your Gmail email address if that's alright. Please let me know if you've received it!

Best, Patrick

— Reply to this email directly, view it on GitHub https://github.com/xuyiqing/tjbal/issues/10#issuecomment-1641131557, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2PKGAIYIIZG52562VCJZLXQ4NSHANCNFSM6AAAAAA2O55QII . You are receiving this because you commented.Message ID: @.***>

-- Sent from IPhone. Please pardon typos and brevity.

pchest commented 1 year ago

Thanks! And will do!