• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Transpose matrix

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Is it possible to read a CSV file with multiple columns and do a transpose matrix on it?

Thanks,
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ofcourse that is possible. So, you want to write a program that does this? What code have you written yourself, and where exactly did you get stuck?
 
Akil Kumar
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the response. I have a spread sheet where in I have multiple columns of data. I am exporting that spread sheet to a CSV file and reading it from the client side. I want to keep the first column as is and transpose matrix the rest of the columns.

Ideally I would like to create a two dimensional array out of it and index through multiple columns for each row of data. I have attached the spread sheet also for the reference. I have the following code to read the CSV file.



 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Akil Kumar wrote: I have a spread sheet where in I have multiple columns of data. I am exporting that spread sheet to a CSV file and reading it from the client side. I want to keep the first column as is and transpose matrix the rest of the columns.



Surely this transpose only makes sense if the total number of columns is just one greater than the total number of rows. If not then you will have a ragged matrix and will either have some rows without data in some columns or some columns without first row data.




 
Akil Kumar
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote:Ofcourse that is possible. So, you want to write a program that does this? What code have you written yourself, and where exactly did you get stuck?



Hello,

How can I index multiple columns of variable length while reading a CSV file? Let's say I have col A, col B, col C and so on. I want to create a 2D array with col A & B then col A & C then col A & D and so on. Moreover can any of the columns contain empty cells in between? Please help me how to achieve this?

Thanks,
 
James Sabre
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Akil Kumar wrote:
How can I index multiple columns of variable length while reading a CSV file? Let's say I have col A, col B, col C and so on. I want to create a 2D array with col A & B then col A & C then col A & D and so on. Moreover can any of the columns contain empty cells in between? Please help me how to achieve this?



I don't see where creating a transpose matrix comes into this and don't fully understand the requirement but it seems to me you need to use the Facade pattern. Having created your 2 D array from the CSV file you then define a class along the lines of


which defines a mapping between the cols of the original and the desired and an access method to do the conversion.

It is trivial to add methods to return the number of rows and the number of columns. It is trivial to modify the getElement() method to handle non-existent rows or columns.

You then us this as


then use the access getElement() method to access the pseudo matrix.
 
Akil Kumar
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Sabre wrote:

Akil Kumar wrote:
How can I index multiple columns of variable length while reading a CSV file? Let's say I have col A, col B, col C and so on. I want to create a 2D array with col A & B then col A & C then col A & D and so on. Moreover can any of the columns contain empty cells in between? Please help me how to achieve this?



I don't see where creating a transpose matrix comes into this and don't fully understand the requirement but it seems to me you need to use the Facade pattern. Having created your 2 D array from the CSV file you then define a class along the lines of


which defines a mapping between the cols of the original and the desired and an access method to do the conversion.

It is trivial to add methods to return the number of rows and the number of columns. It is trivial to modify the getElement() method to handle non-existent rows or columns.

You then us this as


then use the access getElement() method to access the sudo matrix.





Hello,

Thank you for the response. I apologize for not being clear. I have attached the excel sheet for your reference. I still did not get the answer for my question. Forget about the transpose matrix for now. Can you explain what is a facade pattern? Why do I have to use that pattern?

Thanks,
 
James Sabre
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Akil Kumar wrote:

Thank you for the response. I apologize for not being clear.
I have attached the excel sheet for your reference. I still did not get the answer for my question.



I provided an answer! It may not be the answer you want but then again I can't be sure what you really want.


Forget about the transpose matrix for now. Can you explain what is a facade pattern? Why do I have to use that pattern?


Google for the Facade pattern.

You don't have to use the Facade pattern. It just makes things easy to use without having to create copies for every possible column set you might need. You just create an instance of the Facade for each set of columns you want to work with and then work only with Facade instances and not directly with the CSV matrix.

P.S. I have no idea how to get hold of the excel sheet you say you have attached.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic