Closed VladimirAlexiev closed 6 months ago
There's a 'spread': https://bioinf.shenwei.me/csvtk/usage/#spread
Uh-oh, I had 0.24. Thanks! After upgrading, I get exactly what I need:
csvtk space2tab test.txt|csvtk spread -t -k t -v c|csvtk pretty -t
module Class DatatypeProperty ObjectProperty
------- ----- ---------------- --------------
address 1 2 3
agent 4
hi @shenwei356 Does it make sense to add scatter
as a synonym of spread
?
scatter
is a better match for gather
: it even rhymes :-)
Not really :). scatter
sounds like the scatter plot.
gather
and spread
are from the R package tidyr
. They perform opposite operations.
$ csvtk -h
Commands for Data Transformation:
fold fold multiple values of a field into cells of groups
gather gather columns into key-value pairs, like tidyr::gather/pivot_longer
sep separate column into multiple columns
spread spread a key-value pair across multiple columns, like tidyr::spread/pivot_wider
transpose transpose CSV data
unfold unfold multiple values in cells of a field
@shenwei356 Yes: gather != spread = scatter
.
"spread" and "scatter" mean the same (in this context", and "scatter" rhymes better with "gather".
I don't know tidyr
, that's why I guessed there should be "scatter" as the opposite of "gather".
Does it make sense to add scatter as a synonym of spread?
OK. But spread
remains the main name, for consistence with tidyr
, a popular R package widely used for table manipulation.
sure!
done.
Can you add a command that's opposite of "gather"?
I have a file like this:
I want to convert it to:
I don't know what would be an appropriate name, maybe "scatter"? Could be invoked like this
where -f is an OPTIONAL list of key values to be used for sorting the output columns.
I don't have a useful case for multiple key or value columns, but I guess that is possible . Eg from
to something like
Multiple
--key
make sense only for a very few values in the key columns.