58095

skip columns in read.table without knowing how many columns

Question:

So i know you can skip columns with read.table by providing a NULL to colClasses vector, but this is usually only helpful if you know how many columns are in your table.

What if I want to skip first 2 columns of table but read all the rest (which I know are numeric). Something like:

colClasses = c(NULL,NULL,rep("numeric", k))

except I don't know what k is. What would be best way to handle this?

Answer1:

If you use the default white-space separation on a file named "fil.txt" then use this

colClasses = c(NULL,NULL,rep("numeric", count.fields("fil.txt")[1] -2 ))

If you use a different separator then something like

colClasses = c(NULL,NULL,rep("numeric", count.fields("fil.txt", sep=",")[1] -2 ))

Recommend

  • FF in R: No Applicable Method for 'recodeLevels'
  • R: splitting a numeric string
  • Select Data After Specific Date
  • Deserialize into polymorphic collection using Jackson without using @JsonTypeInfo
  • Plot a table with R
  • R Impute NA's by Linear Increase Depending on Time Interval
  • How to customize whisker lines on a geom_box plot differently than the lines of the box itself
  • addressing in assembler
  • How to Divide an array on c#?
  • Is mp4 stream able with ffserver?
  • Returning this from a constructor function in JS
  • Neo4j: Filter nodes based on aggregate function
  • Tools for understanding HTML layout
  • runtime-check whether an instance (Base*) override a parent function (Base::f())
  • What is corresponding c++ data type to SQL numeric(18,0) data type?
  • Where these are stored?
  • JSON encode and decode on PHP
  • Is there a package like bigmemory in R that can deal with large list objects?
  • Primefaces :radioButton inside a ui:repeat
  • CSS bleed-through with cfinput type=“datefield”
  • how do i write assembly code from c#?
  • R convert summary result (statistics with all dataframe columns) into dataframe
  • android.support.v7.widget.Toolbar VectorDrawableCompat IllegalStateException when using support lib
  • Authentication in Play! and RestEasy
  • Breaking out column by groups in Pandas
  • Unable to get column index with table.getColumn method using custom table Model
  • How to determine if there are bytes available to be read from boost:asio:serial_port
  • jQuery ready not fired after rails link_to is clicked
  • Bad request using file_get_contents for PUT request in PHP
  • Refering to the class itself from within a class mehod in Objective C
  • Initializer list vs. initialization method
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • Matrix multiplication with MKL
  • Linker errors when using intrinsic function via function pointer
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • SQL merge duplicate rows and join values that are different
  • LevelDB C iterator
  • Can't mass-assign protected attributes when import data from csv file
  • How can i traverse a binary tree from right to left in java?