Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reshape data in long format to data in mousetrap format as array #4

Closed
sbrockhaus opened this issue Jul 29, 2016 · 1 comment
Closed

Comments

@sbrockhaus
Copy link
Contributor

This is a general question on whether the mousetrap package already conains the following functionality. I convert a mousetrap-object into long format, add one or several new variables to the long data and then I would like to transform the data back to mousetrap format. Consider the following example code:

library(mousetrap)
## example from package 
mt_example <- mt_import_mousetrap(mt_example_raw)

## reshape data into long format 
tr <- mt_reshape(data = mt_example, use = "trajectories", use2 = "data", 
                 use2_variables = c("Condition"), 
                 aggregate = FALSE) 

## add a new fancy variable 
tr$new_var <- rnorm(nrow(tr))

## now reshape back to mousetrap object like mt_example?
?

Is there a possibility to reshape tr back to a mousetrap object like mt_example, where new_var is part of trajectories like "timestamps" "xpos" "ypos"?

@PascalKieslich
Copy link
Owner

PascalKieslich commented Aug 25, 2016

Thanks for the question/suggestion. Data in long format (which results in your example from using mt_reshape) can be imported using mt_import_long.

However, thanks for pointing out the issue with importing newly created variables. So far, mt_import_long has not supported custom variables. However, I introduced an additional argument add_labels to the function that allows for importing any additional variables. This is available now on GitHub and will be included in the next release.

Edit Aug 26, 7:00 pm:
I just reworked the function again to be more consistent with the previously released version of the package. The solution for your example now looks like this.

Short version (as the defaults for x- and y-positions and timestamps fit):

mt_data <- mt_import_long(tr, add_labels="new_var"))

Long version (specifying all arguments)

mt_data <- mt_import_long(tr,
  xpos_label = "xpos", ypos_label="ypos", timestamps="timestamps", add_labels="new_var"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants