readCards: Function to read a data file defined by positions with...

Description Usage Arguments Value Examples

View source: R/readPos.R

Description

Function to read a data file defined by positions with disaggregated data by cards and save it in a DF

Usage

1
readCards(datasource, positions, ncards)

Arguments

datasource

Path of a data file with plain text format and disaggregated data by cards (eg: .dat or .asc not associated with a xml)

positions

Path of a csv that specifies the name of the variable, type and positions that have information in data file. The csv must be the following structure, otherwise this function will not work: Four first columns (you can add more at the rigth of these four, they will be not used but can help you to add comments or somewhat) 1 - variables: that column contains the name of the variables to work, the name that you write there will be the colname in R data frame. Names don't allow blank spaces, you must replace it with other character. 2 - type: specifies the type of the variable, allows "character", "single", "multiple" or "numeric". 3 - start: positions that starts the range of data that will definie the variable. 4 - finish: positions that finish the range of data that will definie the variable. 5 - card: number of card where data's variable is allowed. Should be numeric value (eg: "2" when the variable is in the second line of each card. In file of 5 cards it will the following rows: 2,6,11,16...)

ncards

Number of cards of the file. Eg: when a file have 6 lines for each interviwed (register) the number of cards will be 6. Integer values allowed only.

Value

A data frame with as many columns as rows have the csv (with their "variable" names) and as many rows as rows have the data file.

Examples

1
2
3
4
5
6
7
8
readPos(datasource = "C:/Desktop/datum.dat", positions = "C:/Documents/map.csv" )

CSV structure example(headers must be like this): 

   variable,type,start,finish,card
   sex,single,5,6,1
   age,numeric,12,14,1
   satisfaction,character,4,7,3

ODECdmorales/readPos documentation built on Oct. 30, 2019, 10:19 p.m.