mt_import_long issues reading column names
I'm having issues with the mt_import_long function. It produces an error message when I try to import a csv file created by matlab.
"Warning message: In mt_import_long(data, xpos_label = "XPos", ypos_label = "YPos", : After removing trajectory data, more than one unique row per mt_id remains."
I believe the issue is related to reading my column names for the mt_seq_label. When I open the csv file in excel, delete the column name, manually retype it, and rerun the r script, it works. I have no clue why this happens or why it works after I open and retype the column name in excel. I've tried renaming columns in R before using the mt_import_long function and it still produces the error message. The function only works after I open the data files in excel and retype the column name.
Thanks,
Carrie
Comments
Hi Carrie,
without seeing the data I can only guess, but one issue that sometimes occurs when you read csv files into R is that the column names are misplaced, i.e., shifted by one column (which can e.g. happen if the csv contains row numbers which are ignored during data import). Did you take a closer look at the data data.frame after you read the data into R to see whether all data are in the correct columns and whether there are no additional columns that you would not expect to see there?
Best,
Pascal
Thanks for the quick reply! I have checked and the column names are in the correct position.
Carrie
Hi Carrie,
that's good, then a shifted column order does not seem to cause the issue.
I think you would have to provide me with some additional information so I can help you further. Specifically, could you post the code you use to read in the data into R and the complete command when you run mt_import_long? And could you share a few example rows of your dataset that you pass on to mt_import_long?
Best,
Pascal
Here are screenshots. Thank you.
Code to read and mt_import_long
data imported into R
Hi Carrie,
sorry for the delayed reply, I was on vacation.
Thanks for sharing the screenshots. In principle everyhing looks fine to me. However, depending on whether you have data from one or several subjects in your
datadata.frame, you could changemt_id_label = "Trial"tomt_id_label = c("SubjectID", "Trial")to ensure that unique trials are identified. In addition, I don't know if the values in the Time, StartTime and EndTime columns are constant within a trial - if they are are not, it would be good to remove these columns before calling mt_import_long.Best,
Pascal
Just to clarify (as background information):
The warning message above ("Warning message: In mt_import_long(data, xpos_label = "XPos", ypos_label = "YPos", : After removing trajectory data, more than one unique row per mt_id remains.") is outputted by mt_import_long when any other column in your dataset that was not specified as xpos/ypos/timestamps_label varies within the trial.
So in case there are any additional variables that vary within the trial, you could either specify them via the add_labels argument or exclude them before calling mt_import_long.