Page 1 of 1

Transforming string variables

Posted: Mon Nov 16, 2020 9:43 pm
by agoodquestion
Hello!
I'm new to jamovi and liking it so far. I'm having trouble with the transform function, though. I'm working off a survey dataset that was (unfortunately) collected in Google Forms, so I have a couple of string variables generated from "check all that apply" questions that just list all the options selected by each respondent in one cell, separated by commas. I'm trying to create several Transform variable with a formula using the CONTAINS function in order to indicate whether the original variable contains a given string. The survey question had 10 check all that apply options + other. So I'm trying to create 10 Transform variables, one for each of the options that would indicate 1 if the original variable contains it, and 0 or blank if it doesn't. I've been trying to write this formula in the transform, but nothing works. I keep getting a "mis-specified" error message.

Please help!

Thank you so much in advance!!

Re: Transforming string variables

Posted: Mon Nov 16, 2020 10:03 pm
by jonathon
hi laura,

the mis-specified error is jamovi working correctly, and telling you that your formula isn't specified correctly. take a look at it, and see if you can figure out what's wrong with your formula.

if you can't, then feel free to post it here, and we'll take a look.

kind regards

jonathon

Re: Transforming string variables

Posted: Tue Nov 17, 2020 3:41 pm
by agoodquestion
hello jonathon,

thank you for your reply. i understand that jamovi is correctly identifying my formula as mis-specified, but i can't figure out what's wrong with the formula. here's what i've tried:

if $source CONTAINS 'Screening and diagnosis of hepatitis C' use 1

i know that typing CONTAINS in the pull-down box that's meant to have a mathematical operator is not right, so i tried using == instead, which got rid of the mis-specified error, but of course returned no results, since none of the cases in the source variable contain just that string - they contain more than that.

also, when i click on the transform button, a new variable does get created next to the original variable, but the entire column is red and there's an error message that says circular logic, even before i put in any formulas.

could you please help me figure this out!

many thanks,
-lina

Re: Transforming string variables

Posted: Tue Nov 17, 2020 6:09 pm
by MAgojam
Hi, lina.
Take a look at the attached screenshot, which shows a small example of using the CONTAINS () function.
As you can see, the search is case sensitive, reporting 1 when successful.
Screenshot_Trasform.PNG
Screenshot_Trasform.PNG (68.35 KiB) Viewed 5897 times
Cheers,
Maurizio

Re: Transforming string variables

Posted: Tue Nov 17, 2020 9:56 pm
by agoodquestion
thank you so much, maurizio!
this CONTAINS formula is exactly what i needed!

Re: Transforming string variables

Posted: Sat Jun 10, 2023 2:10 pm
by reason180
Thanks. This is helpful, but can someone provide a full specification of what CONTAINS does? Within jamovi, CONTAINS is described as follows:
"CONTAINS(item1, item2, item3, ...in1, in2, in3)".
But how does jamovi know which arguments counts as "item" terms and which count as "in" terms? And how does it know which "in"s should be searched to identify which "item"(s)?

Re: Transforming string variables

Posted: Sun Jun 11, 2023 11:43 pm
by MAgojam
Hey @reason180,
may suggest a look here:
https://github.com/jamovi/jamovi/blob/c ... #L423-L435

Cheers,
Maurizio

Re: Transforming string variables

Posted: Tue Jun 13, 2023 12:48 am
by jonathon
> But how does jamovi know which arguments counts as "item" terms and which count as "in" terms?

you can name the arguments:

CONTAINS(item1=..., item2=..., in1=...)

i think it searches all the in's.

jonathon