Transforming string variables

General help and assistance with jamovi. Bug reports can be made at our issues page: https://github.com/jamovi/jamovi/issues . (If you're unsure feel free to discuss it here)
Post Reply
agoodquestion
Posts: 6
Joined: Mon Nov 16, 2020 9:30 pm

Transforming string variables

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

Re: Transforming string variables

Post 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
agoodquestion
Posts: 6
Joined: Mon Nov 16, 2020 9:30 pm

Re: Transforming string variables

Post 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
User avatar
MAgojam
Posts: 421
Joined: Thu Jun 08, 2017 2:33 pm
Location: Parma (Italy)

Re: Transforming string variables

Post 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 5316 times
Cheers,
Maurizio
agoodquestion
Posts: 6
Joined: Mon Nov 16, 2020 9:30 pm

Re: Transforming string variables

Post by agoodquestion »

thank you so much, maurizio!
this CONTAINS formula is exactly what i needed!
User avatar
reason180
Posts: 274
Joined: Mon Jul 24, 2017 4:56 pm

Re: Transforming string variables

Post 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)?
User avatar
MAgojam
Posts: 421
Joined: Thu Jun 08, 2017 2:33 pm
Location: Parma (Italy)

Re: Transforming string variables

Post by MAgojam »

Hey @reason180,
may suggest a look here:
https://github.com/jamovi/jamovi/blob/c ... #L423-L435

Cheers,
Maurizio
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Transforming string variables

Post 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
Post Reply