cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Have your say in shaping JMP's future by participating in the new JMP Wish List Prioritization Survey
Choose Language Hide Translation Bar
Madwolf
Level II

Recode numerical days into Monday, Tuesday, Wednesday etc

Hi, I have a column that is indicated as days, in ordinal data.

 

How can I recode it, such that they are (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday)?

 

Currently:

 

1 = Wednesday

2 = Thursday

3 = Friday

4 = Saturday

5 = Sunday

6 = Monday

7 = Tuesday

9  =Wednesday

.....

416 = Friday

417 = Saturday

418 = Sunday

 

Is there a way to recode it without me having to type Mon - Sun all the way from 1 to 418?

1 ACCEPTED SOLUTION

Accepted Solutions
Jeff_Perkinson
Community Manager Community Manager

Re: Recode numerical days into Monday, Tuesday, Wednesday etc

Building on @txnelson's solution, you can use a Formula column with the Modulo() function that he showed, along with the Value Labels property.

 

2021-01-27_09-16-23.770.png

The attached data table has this example.

 

-Jeff

View solution in original post

5 REPLIES 5
txnelson
Super User

Re: Recode numerical days into Monday, Tuesday, Wednesday etc

Here is an example of a script that will create a new column with the desired values

Names Default To Here( 1 );

// Create an Example data table
dt = New Table( "Example", add rows( 418 ), New Column( "weekday", set each value( Row() ) ) );

// Create a new column Using a script
dt << New Column( "Weekday 2",
	character,
	set each value(
		theList = {"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday"};
		theList[Mod( :weekday, 7 ) + 1];
	)
);
Jim
Madwolf
Level II

Re: Recode numerical days into Monday, Tuesday, Wednesday etc

Thank you so much. However, if I may ask, how do I do it, such that the new column is inside my existing table?

For instance, my existing table name is transaction_data.

Which are the field that I needed to change to "transaction_data" above, without the need to create a new table?
Jeff_Perkinson
Community Manager Community Manager

Re: Recode numerical days into Monday, Tuesday, Wednesday etc

Building on @txnelson's solution, you can use a Formula column with the Modulo() function that he showed, along with the Value Labels property.

 

2021-01-27_09-16-23.770.png

The attached data table has this example.

 

-Jeff
Madwolf
Level II

Re: Recode numerical days into Monday, Tuesday, Wednesday etc

Thank you so much!!

Re: Recode numerical days into Monday, Tuesday, Wednesday etc

Select the column with the current values (1..7). Select Cols > Column Info. Select Column Properties > Value Labels. Define the character string label for each data value.