Comments (7)
I see! You can use the function API to accomplish this with select. e.g.:
function firstNKeys(n) {
return items => Object.keys(items[0]).slice(0, n)
}
output = tidy(input,
mutate({ foo: 'foo' }),
select([firstNKeys(1), 'foo', everything()])
);
Or
function myCustomKeys(items) {
const keys = Object.keys(items[0])
return [keys[0], 'foo', ...keys.slice(1)]
}
output = tidy(input,
mutate({ foo: 'foo' }),
select([myCustomKeys])
);
from tidy.
You can use selectors with select to make this less painful, e.g.:
tidy(input,
mutate({ foo: 'foo' }),
select(['foo', everything()])
);
This puts foo
as the first key. Does that work for you?
from tidy.
That's interesting but I don't think it covers my use case. I wanted to insert foo
as the second column. This may sound like an absurdly nitpicky requirement but it was the most logical ordering of the sheet. I was also converting something from d3-nest to use tidjs and i wanted the outputs to match exactly so i could easily ensure the conversion was successful.
from tidy.
Instead of adding this as an option to mutate
maybe there's another tidy function called reorder
or move
that would allow you to do specify a column name and its new index like:
reorder('foo', 1)
from tidy.
Thanks for these examples. In your first example, would the first key be duplicated when you call everything()
or does it somehow know not to include it?
I think I would still find it easier and more readable to have it in some kind of tidy function but I understand if this is out of scope for what you want to do.
from tidy.
Once a key has been selected, it stays in that spot, so there's no issue duplicating it with everything(). We could add firstKeys
and lastKeys
as selectors, but they'd operate identically to the firstNKeys example I put above, so I'd recommend for now just making that a utility function you use in your code base. If there's sufficient other interest we can add it, but it seems a bit niche to me at least right now.
from tidy.
Sounds good
from tidy.
Related Issues (20)
- Bug: groupBy exports do not respect addGroupKeys
- Bug: mapEntry not called on entriesObject
- valuesFillMap for pivotWider() not being applied HOT 2
- Feedback on unexpected behavior in groupBy HOT 9
- Should groupBy's addGroupKeys be on by default?
- Allow type guards for filter HOT 2
- leftJoin followed by select everything has unexpected dropped columns
- Typescript type error? HOT 1
- Mutate should pass the index
- GroupBy fails with Dates HOT 1
- arrange should accept accessors
- Update docs to reflect keys being prepended now HOT 1
- Feature Request: add a boolean flag to turn on/off debug HOT 1
- New Architecture
- Type error when using groupBy after mutate HOT 2
- New summarizer: nWhere? HOT 3
- complete, is not parsing the original data HOT 1
- import fail HOT 5
- nested objects? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tidy.