- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
replacing numbers with strings
hey,
i have a column COL_A, which has 31 rows for wach number between 1 - 31 ( 31 rows of 1, 31 rows of 2 .... etc), and i want to replace those numbers with 31 strings in a specifiec order, for example:
if my string are in this order: horse, cat, dog ....etc, i want to replace the 1's with horse, the 2's with cat, the 3's with dog...., what is the best and fastest way to do it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: replacing numbers with strings
Go to the column header for the column you want to change the values for, and right click on the header and select "Recode"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: replacing numbers with strings
I agree with Recode ... but there are other options depending on your usage:
1. A script with If-Then-Else statements ... so you would have If C1=="1" Then "Horse" and so on. Even for 31, that can get cumbersome ... but possible. I will typically only use this for max of ~6 items.
2. LinkID / LinkReference table. I use this a ton - we run loads of experiments in our development line (I am a happy/busy statistician :) ) with condition keys on the parts we generate done as letters A-Z, and so on. When setting things up I will always have a core table before randomization with the condition in a column and the conditions in other columns. The COndition is made a LinkID
Since we do many tests, in the results we only use the Condition ID (A-Z) and any specific test information (e.g. where on a part we take the data), and then use LinkReference on the Condition in the results table to go back to the Experimental Conditions table. Incredibly powerful!
In your case you could simply have a column with 1-31, and a second column with the values Horse, Cat, Dog, etc. Then use the LinkIDReference feature to get at the values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: replacing numbers with strings
(Also agree with recode.)
A script for this might look something like this
dt = Open( "$sample_data/big class.jmp" );
dt << New Column( "group", character );
label = {"baby", "toddler", "toddler", "pre-k", "k", "1st", "2nd", "3rd", "4th", "5th", "6th", "middle", "middle", "middle", "high", "high", "high"};
For Each Row( group = label[age] );
Grouped ages
The if-then-else approach might be better if your data isn't contiguous, starting at one, or if there are only a few groups.