These reports are coming from quickbooks, downloaded as Excel files. Notice that the left column is this nested hierarchy based on the left spacing.
I need to separate Description column into separate columns based on the number of leading spaces on the left.
As I've been working with financial reports recently, these are super common and extremely difficult to work with. Is there a package or function for importing this type of data?
Here is example reproducible input dataframe:
df1 <- structure(list(Description = c("asset", " current asset", " bank acc",
" banner", " clearing",
" total bank accounts",
" total current assets"),
Total = c(NA, NA, NA, 10L, 20L, 30L, 30L)),
.Names = c("Description", "Total"),
class = "data.frame",
row.names = c(NA, -7L))
Select the column you want to split. Ensure the column is a text data type. Select Home > Split Column > By Number of Characters. The Split a column by Number of Characters dialog box appears.
Click the “Data” tab in the ribbon, then look in the "Data Tools" group and click "Text to Columns." The "Convert Text to Columns Wizard" will appear. In step 1 of the wizard, choose “Delimited” > Click [Next]. A delimiter is the symbol or space which separates the data you wish to split.
To split a column into multiple columns in the R Language, we use the separator() function of the dplyr package library. The separate() function separates a character column into multiple columns with a regular expression or numeric locations.
You can try tidyxl
and unpivotr
for these Excel wrangling tasks. Here are the docs:
Here's a nice tutorial: https://blog.davisvaughan.com/2018/02/16/tidying-excel-cash-flow-spreadsheets-in-r/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With