Feature?: Convert Text to Factor/Integer

Discuss the jamovi platform, possible improvements, etc.

by dak » Tue Feb 19, 2019 10:25 pm

Use case:
- Ordinal data as text in Excel/csv (e.g., "Strongly Agree", "Agree", etc).
- Imported into Jamovi as Text
- Want to calculate mean (or do other numeric things like "greater than" to get all Agree's)

The only way I can think of is to use Transform to create an integer variable. But, the new variable is treated as Nominal (since the original was) so it cannot immediately be treated as a number. Plus, a transformed variables cannot have labels, so one must keep both variables or copy and paste the transformed values into yet another variable, label it, and remove the two originals.

Am I missing a easier way?

If not, could there be a button to convert a text variable into a numeric variable? People could also use it to "re-level" an existing factor. Or, maybe factor it automatically if someone tries changing the data type from text to an integer., Or, have an option for (or default to) "stringsAsFactors" on import (I know some people dislike that, but it has uses).
dak
 
Posts: 1
Joined: Tue Feb 19, 2019 10:06 pm

by jonathon » Wed Feb 20, 2019 12:47 am

hi,

yeah, this particular use-case is a little awkward, but it is do-able.

> The only way I can think of is to use Transform to create an integer variable. But, the new variable is treated as Nominal (since the original was) so it cannot immediately be treated as a number.

so it should be an 'integer nominal', so you should still be able to use it as a number. but you *can* set the measure type to whatever you want. see here:

Screen Shot 2019-02-20 at 11.35.56.png
Screen Shot 2019-02-20 at 11.35.56.png (135.29 KiB) Viewed 59 times


(you've probably figured this out already, but there is a subtle trap if you keep the `else use $source` rule at the end. because $source is text, the recoder looks at all the possible outcomes and sees that it must make the result text as well. if you change the else clause to `else use NA` then *all* the possible outcomes are integer, and it makes the column integer).

> a transformed variables cannot have labels, so one must keep both variables

yeah, this is the awkward bit. i'm thinking of adding a feature where one can specify value label pairs in the recode.

i.e. `if ... use (+2, 'Strongly Agree')`

> If not, could there be a button to convert a text variable into a numeric variable?

yeah, i've pondered this, but it introduces complexities to do with importing ... i.e. when you take a data file with all it's analyses, and replace the data with a new data set (using jamovi like a script). these may be solveable - tbh it's been a while since i've thought about it.

but yeah, it is a bit akward that you have to keep two versions of a variable kicking around.

let us know if you get stuck with anything

jonathon
User avatar
jonathon
 
Posts: 692
Joined: Fri Jan 27, 2017 10:04 am


Return to General