cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
UserID16644
Level V

How to subset data with some headers in rows?

Hi, I have a big data which has headers inside some rows. I wanted to subset the data per header with its value. My data looks something like this:

 

Header 1Column 2Column 3Column 4
1111
1111
1111
Header 2Column 2Column 3Column 4
2222
2222
Header 3Column 2Column 3Column 4
3333
3333
3333

 

 

I need to subset the data per Header, so I should have Header 2 with 

Header 2Column 2Column 3Column 4
2222
2222

Header 3

Header 3Column 2Column 3Column 4
3333
3333
3333

 

I tried creating a Flag column, assign 1 to each header then subset. But the result is incorrect as it subset 1 and blank with Subset 1 with all the headers. This is what I created:

CSV << New Column ("Flag", Numeric);
r = CSV << getRowsWhere( Contains( :Header 1, "Header " ));
Column(CSV, "Flag")[r] = 1;

Please help

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to subset data with some headers in rows?

Move Header1 "down" from the column name (if it is there),

jthi_2-1731395223795.png

create flag column with formula such as

If(Starts With(:Column 1, "Header"),
	flag = :Column 1
);
flag;

jthi_0-1731395148939.png

Then you can subset using that new column as By

jthi_1-1731395197404.png

 

 

-Jarmo

View solution in original post

10 REPLIES 10
jthi
Super User

Re: How to subset data with some headers in rows?

Move Header1 "down" from the column name (if it is there),

jthi_2-1731395223795.png

create flag column with formula such as

If(Starts With(:Column 1, "Header"),
	flag = :Column 1
);
flag;

jthi_0-1731395148939.png

Then you can subset using that new column as By

jthi_1-1731395197404.png

 

 

-Jarmo
UserID16644
Level V

Re: How to subset data with some headers in rows?

Sorry, Im a little bit confused. How did you create Header1 Column?

jthi
Super User

Re: How to subset data with some headers in rows?

Using Column Names -> Move down

jthi_0-1731403898746.png

 

-Jarmo
hogi
Level XII

Re: How to subset data with some headers in rows?

If(Starts With(:Column 1, "Header"),
	flag = :Column 1
);
flag;

 

cool , temporary flag - available also for subsequent rows.

jthi
Super User

Re: How to subset data with some headers in rows?

You might want to make it a bit more robust by making sure it has been initialized for example by using As Constant() (or If(Row() == 1,....). In this case is wasn't necessary so I didn't bother with it

As Constant(flag = "");
If(Starts With(:Column 1, "Header"),
	flag = :Column 1
);
flag;

Also the readability might improve with something like

As Constant(flag = "");
If(Starts With(:Header 1, "Header"),
	flag = :Header 1
,
	flag
)

You just want to "return" the value you wish to see in rows.

-Jarmo
UserID16644
Level V

Re: How to subset data with some headers in rows?

I mean Column 5, sorry for the confusion. Is that from the formula? Im using JMP16 and it has an error

Name Unresolved: flag in access or evaluation of 'flag' , flag/*###*/
jthi
Super User

Re: How to subset data with some headers in rows?

After having correct column headers, create new column with a formula

jthi_0-1731477946052.png

 

-Jarmo
UserID16644
Level V

Re: How to subset data with some headers in rows?

Can this be done using JSL?

jthi
Super User

Re: How to subset data with some headers in rows?

Yes. I think JMP can record all these actions and you can get the script from enhanced log (or build workflow)

-Jarmo