turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Calculating mean for a set of columns in jsl

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Apr 19, 2016 9:03 AM
(5626 views)

I have a set of column names in a list called list_1, now I want to calculate the mean for each column, but the thing is I do not want to include all the rows in the column when calculating the mean, i have another pre-defined variable that selects specific rows. How do I calculate the mean of the column by selecting the specified rows instead of stepping down through all the rows?

for example i want the mean to be calculated based on rows 1,3,4,5,9 on a specific column

dt << current data table;

for (p=1,p<=nitems(list_1), p++,

col = list_1

;

mean = col mean(dt :col );

)

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Apr 19, 2016 9:41 AM
(9723 views)

The col functions appear to ignore the excluded row state. This works however:

//for example i want the mean to be calculated based on rows 1,3,4,5,9 on a specific column

dt = New Table**(** "testmean", Add Rows**(** **10** **)**,

New Column**(** "C1", Numeric, Continuous, Format**(** "Best", **12** **)**,

Set Values**(** **[****1**, **2**, **3**, **4**, **5**, **6**, **7**, **8**, **9**, **10]** **)** **)**,

New Column**(** "C2", Numeric, Continuous, Format**(** "Best", **12** **)**,

Set Values**(** **[****5**, **4**, **3**, **6**, **7**, **2**, **3**, **6**, **5**, **4]** **)** **)**

**)**;

sel_rows = **[****1**,**3**,**4**,**5**,**9]**;

list_1 = **{**"C1", "C2"**}**;

for **(**p=**1**, p <= nitems**(**list_1**)**, p++,

one_col = list_1**[**p**]**;

mean = mean**(**column**(**dt, one_col **)[**sel_rows**])**;

show**(**p, mean**)**;

**)**;

1 REPLY

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Apr 19, 2016 9:41 AM
(9724 views)

The col functions appear to ignore the excluded row state. This works however:

//for example i want the mean to be calculated based on rows 1,3,4,5,9 on a specific column

dt = New Table**(** "testmean", Add Rows**(** **10** **)**,

New Column**(** "C1", Numeric, Continuous, Format**(** "Best", **12** **)**,

Set Values**(** **[****1**, **2**, **3**, **4**, **5**, **6**, **7**, **8**, **9**, **10]** **)** **)**,

New Column**(** "C2", Numeric, Continuous, Format**(** "Best", **12** **)**,

Set Values**(** **[****5**, **4**, **3**, **6**, **7**, **2**, **3**, **6**, **5**, **4]** **)** **)**

**)**;

sel_rows = **[****1**,**3**,**4**,**5**,**9]**;

list_1 = **{**"C1", "C2"**}**;

for **(**p=**1**, p <= nitems**(**list_1**)**, p++,

one_col = list_1**[**p**]**;

mean = mean**(**column**(**dt, one_col **)[**sel_rows**])**;

show**(**p, mean**)**;

**)**;