Last data update: 2014.03.03

R: Reads microdata for the 2010 decennial census provided by the...
censo2010R Documentation

Reads microdata for the 2010 decennial census provided by the INE

Description

This function reads the microdata file for the Spanish 2010 Census.

Usage

censo2010(census.file, columns = NULL, summary = TRUE)

Arguments

census.file

The name of the microdata file

columns

Names of the columns that need to be read; NULL for all

summary

Whether just to print a summary of the contents of the file; defaults to TRUE

Details

This function reads microdadata file for the 2010 decennial census in Spain.

Mind that a powerful computer may be needed to read the full census file. For this reason, the summary parameter is set to TRUE by default. Users are advised to review the contents of the file first (keeping the summary=TRUE default) to explore its contents and then call the function again after setting the columns parameter apropriately to read just the desired subset of columns.

Reading the full set of columns may require a computer with almost 20GB of RAM.

Value

By default, the function just prints a summary of the contents of the microdata file.

If the summary is set to FALSE, the function returns a data.set. This class is defined in package memisc. Most users will want to transform the output to a regular data.frame using function as.data.frame.

Author(s)

CarlosNeira with minor modifications by Carlos J. Gil Bellosta after data file format changes.

Examples

## The first 1000 lines from the census file are provided within the package
c.file <- system.file("extdata", "sampleCenso2010.txt", package = "MicroDatosEs")

# Get a summary of the contents of the census
censo2010(c.file)

# Read a selection of rows
res <- censo2010(c.file, columns = c("cpro", "cmun", "factor"), summary = FALSE)

# Turn them into a regular data.frame
as.data.frame(res)

# Read all rows
res <- censo2010(c.file, summary = FALSE)
summary(res)

summary(as.data.frame(res))

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(MicroDatosEs)
Loading required package: memisc
Loading required package: lattice
Loading required package: MASS

Attaching package: 'memisc'

The following objects are masked from 'package:stats':

    contr.sum, contr.treatment, contrasts

The following object is masked from 'package:base':

    as.array

Loading required package: Hmisc
Loading required package: survival
Loading required package: Formula
Loading required package: ggplot2

Attaching package: 'Hmisc'

The following objects are masked from 'package:memisc':

    %nin%, html

The following objects are masked from 'package:base':

    format.pval, round.POSIXt, trunc.POSIXt, units

> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/MicroDatosEs/censo2010.Rd_%03d_medium.png", width=480, height=480)
> ### Name: censo2010
> ### Title: Reads microdata for the 2010 decennial census provided by the
> ###   INE
> ### Aliases: censo2010
> ### Keywords: manip
> 
> ### ** Examples
> 
> ## The first 1000 lines from the census file are provided within the package
> c.file <- system.file("extdata", "sampleCenso2010.txt", package = "MicroDatosEs")
> 
> # Get a summary of the contents of the census
> censo2010(c.file)
Error in `$<-.data.frame`(`*tmp*`, "valor", value = """") : 
  replacement has 1 row, data has 0
Calls: censo2010 -> create.spss.vals -> $<- -> $<-.data.frame
In addition: Warning messages:
1: In read.table(file.start.end, header = T, sep = "\t", ...) :
  invalid input found on input connection '/home/ddbj/local/lib64/R/library/MicroDatosEs/metadata/censo_2010_mdat1.txt'
2: In read.table(file.start.end, header = T, sep = "\t", ...) :
  incomplete final line found by readTableHeader on '/home/ddbj/local/lib64/R/library/MicroDatosEs/metadata/censo_2010_mdat1.txt'
3: In read.table(file.type, header = T, sep = "\t", ...) :
  invalid input found on input connection '/home/ddbj/local/lib64/R/library/MicroDatosEs/metadata/censo_2010_mdat2.txt'
4: In read.table(file.type, header = T, sep = "\t", ...) :
  incomplete final line found by readTableHeader on '/home/ddbj/local/lib64/R/library/MicroDatosEs/metadata/censo_2010_mdat2.txt'
5: In read.table(file, header = T, sep = "\t", ...) :
  invalid input found on input connection '/home/ddbj/local/lib64/R/library/MicroDatosEs/metadata/censo_2010_mdat1.txt'
6: In read.table(file, header = T, sep = "\t", ...) :
  incomplete final line found by readTableHeader on '/home/ddbj/local/lib64/R/library/MicroDatosEs/metadata/censo_2010_mdat1.txt'
7: In read.table(file, header = T, sep = "\t", ...) :
  invalid input found on input connection '/home/ddbj/local/lib64/R/library/MicroDatosEs/metadata/censo_2010_mdat2.txt'
8: In read.table(file, header = T, sep = "\t", ...) :
  incomplete final line found by readTableHeader on '/home/ddbj/local/lib64/R/library/MicroDatosEs/metadata/censo_2010_mdat2.txt'
Execution halted