Page 1 of 1

extracting part of a text variable

Posted: Fri May 03, 2024 4:19 pm
by Gilles
Hi
I'm working with a data frame which contains a textual variable named "Date". Each cell of this variable contains a date and an hour (dd/mm/yy hh:ss).
I would like to extract the hour in a new variable.
How can I do that with JAMOVI. Is the "split" fonction the good solution. Can you explain me how does it work ?
Furthermore, do you know if it is possible with JAMOVI to concatenate two variables to make one unique variable (in that case, to concatenate the "Date" and the "sortie" variables)
Thank you for your help

Re: extracting part of a text variable

Posted: Fri May 03, 2024 10:15 pm
by jonathon
hi,

i would extract the hour with the formula:

INT(SPLIT(SPLIT(C, ' ', 2), ':', 1))

SPLIT(C, ' ', 2) says split the variable C where ever there are spaces, and give me the 2nd chunk.

SPLIT('04/05/23 05:35', ' ', 1) gives '04/05/23'
SPLIT('04/05/23 05:35', ' ', 2) gives '05:35'

then i would take that value, and split it where the colon is:

SPLIT('05:35', ':', 1) gives '05'

the final step is to convert '05' to a number (at the moment, its being treated like 'text')

INT('05') gives 5 ...

we run this all together and we get:

INT(SPLIT(SPLIT(C, ' ', 2), ':', 1))

cheers
Screenshot 2024-05-04 at 08.09.17.png
Screenshot 2024-05-04 at 08.09.17.png (107.95 KiB) Viewed 6088 times

Re: extracting part of a text variable

Posted: Fri May 03, 2024 10:17 pm
by jonathon
concatenating variables couldn't be simpler:
Screenshot 2024-05-04 at 08.16.25.png
Screenshot 2024-05-04 at 08.16.25.png (157.49 KiB) Viewed 6088 times

Re: extracting part of a text variable

Posted: Sun May 05, 2024 6:12 am
by Gilles
Hi Jonathon
thank you for your answer. It works very well. Jamovi is really an amazing tool