find_column: Find known column name in messy csv files

Description Usage Arguments Details Value Examples

View source: R/find_column.R

Description

Function assists with finding a prior known column name in the event that a csv file is read into and first few rows or columns are potentially junk.

Usage

1
find_column(colName, DT)

Arguments

colName

A name representing a known column, to search for the position

DT

A data.table where the searching should take place

Details

This function returns the position of the column in a list in a row, column order. For example, a list with elements (0, 0) means column name was not found. A list with first element 0 and last element > 0 means the column name is a current column name (0th row) and at column position 1 or greater. (>0, >0) gives the literal index of the cell where the searched name was found.

Value

A 2 entry list representing the row and column where the search criteria was found

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
library(data.table)
## Create fake data
##
DT <- rbindlist(
    list(
        data.table(V1 = "Junk notes as first row", V2=NA, V3=NA, V4=NA), 
        data.table("colA", "colB", "colC", "colD")
    ), fill=TRUE)
    
## Can't find name
find_column("does not exist", DT) # (0, 0)

## Finds name as current column name
find_column("V3", DT) # (0, 3)

## Finds a name
find_column("colA", DT)

bfatemi/easydata documentation built on Oct. 7, 2019, 4:35 p.m.