extracting part of a text variable

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
Gilles
Posts: 2
Joined: Thu May 02, 2024 7:16 pm

extracting part of a text variable

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

Re: extracting part of a text variable

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

Re: extracting part of a text variable

Post 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 116 times
Gilles
Posts: 2
Joined: Thu May 02, 2024 7:16 pm

Re: extracting part of a text variable

Post by Gilles »

Hi Jonathon
thank you for your answer. It works very well. Jamovi is really an amazing tool
Post Reply