Feature?: Convert Text to Factor/Integer

Discuss the jamovi platform, possible improvements, etc.
Post Reply
dak
Posts: 2
Joined: Tue Feb 19, 2019 10:06 pm

Feature?: Convert Text to Factor/Integer

Post by dak »

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).
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Feature?: Convert Text to Factor/Integer

Post by jonathon »

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 8056 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
sydneyplaggemars
Posts: 1
Joined: Thu May 19, 2022 3:22 pm

Re: Feature?: Convert Text to Factor/Integer

Post by sydneyplaggemars »

Hi, I am attempting to follow this and convert my Likert text data to an integer in a transformed variable. However, I keep getting an error message that says "Column 'Definitely' does not exist in the dataset" despite it being visually present in the variable I am looking to transform.
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Feature?: Convert Text to Factor/Integer

Post by jonathon »

if you're wanting to match a text value, you need to wrap it in quotes:

== 'Definitely'

without quotes:

== Definitely

goes looking for a column called Definitely.

jonathon
Post Reply