I have a variable that has 4 lines data with 10 columns across. I want to transpose that data into 10 lines with 4 columns similar to the way you can do it excel thru the paste special commands.
Can anyone get me hints on how to write the code for this with an example?
Thanks, Dan
transpose a variable of data
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: transpose a variable of data
Hi.
It would be a fun little exercise to write a handler to do this, but before you do, go to the dictionary and look up the "transpose" function. You have to split your data into an array first, and then combine it back, but that is simple.
Craig Newman
EDIT. The data has to be regular, that is, cannot have differing numbers of elements in its lines. If it does, back to the cute little handler. Is this a possible issue?
It would be a fun little exercise to write a handler to do this, but before you do, go to the dictionary and look up the "transpose" function. You have to split your data into an array first, and then combine it back, but that is simple.
Craig Newman
EDIT. The data has to be regular, that is, cannot have differing numbers of elements in its lines. If it does, back to the cute little handler. Is this a possible issue?
Re: transpose a variable of data
i'm not very experienced with arrays, so I just use variables for the most part and loop thru them...
my data is structured as it is calling data from a sql database so it always has the same number of elements in each line.
how do I split my data into an array?
Thanks, Dan
my data is structured as it is calling data from a sql database so it always has the same number of elements in each line.
how do I split my data into an array?
Thanks, Dan
Re: transpose a variable of data
Hi.
Why not do what you are comfortable with, and play with arrays later (sooner than later, though). They are powerful, but need a little practice to use effectively.
So back to adorable fun stuff. If you have some data in tab and return delimited form, make two table fields. Put a small amount of your data, perhaps just a few lines with a few elements in each line, into fld 1. This is tab and return delimited text. In a button somewhere:
Step through this, line by line, and watch the variable "accum".
Craig
Why not do what you are comfortable with, and play with arrays later (sooner than later, though). They are powerful, but need a little practice to use effectively.
So back to adorable fun stuff. If you have some data in tab and return delimited form, make two table fields. Put a small amount of your data, perhaps just a few lines with a few elements in each line, into fld 1. This is tab and return delimited text. In a button somewhere:
Code: Select all
on mouseUp
get fld 1
set the itemDel to tab
repeat with y = 1 to the number of lines of it
repeat with u = 1 to the number of items of line y of it
put item u of line y of it & tab after line u of accum
end repeat
end repeat
put accum into fld 2
end mouseUp
Craig
Re: transpose a variable of data
thanks that worked....