Search code examples
emacsorg-mode

Convert a selected region to org table


I have such a block

Function    Description
count   Number of non-NA observations
sum     Sum of values
mean    Mean of values
mad     Mean absolute deviation
median  Arithmetic median of values
min     Minimum
max     Maximum
mode    Mode
abs     Absolute Value
prod    Product of values
std     Bessel-corrected sample standard deviation
var     Unbiased variance
sem     Standard error of the mean
skew    Sample skewness (3rd moment)
kurt    Sample kurtosis (4th moment)
quantile    Sample quantile (value at %)
cumsum  Cumulative sum
cumprod     Cumulative product
cummax  Cumulative maximum
cummin  Cumulative minimum

How could convert it to org table?


Solution

  • Assuming that there is a TAB separating the first and second column, mark the region and say C-u C-u M-x org-table-convert-region RET. The doc string for org-table-convert-region discusses other possibilities for a separator:

    org-table-convert-region is an interactive Lisp closure in
    ‘../org-mode/lisp/org-table.el’.
    
    (org-table-convert-region BEG0 END0 &optional SEPARATOR)
    
    Convert region to a table.
    
    The region goes from BEG0 to END0, but these borders will be moved
    slightly, to make sure a beginning of line in the first line is included.
    
    SEPARATOR specifies the field separator in the lines.  It can have the
    following values:
    
    (4)     Use the comma as a field separator
    (16)    Use a TAB as field separator
    (64)    Prompt for a regular expression as field separator
    integer  When a number, use that many spaces, or a TAB, as field separator
    regexp   When a regular expression, use it to match the separator
    nil      When nil, the command tries to be smart and figure out the
             separator in the following way:
             - when each line contains a TAB, assume TAB-separated material
             - when each line contains a comma, assume CSV material
             - else, assume one or more SPACE characters as separator.