Can anyone please tell me how to read only the first 6 months (7 columns) for each year of the data below, for example by using read.table()?
Year Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2009 -41 -27 -25 -31 -31 -39 -25 -15 -30 -27 -21 -25
2010 -41 -27 -25 -31 -31 -39 -25 -15 -30 -27 -21 -25
2011 -21 -27 -2 -6 -10 -32 -13 -12 -27 -30 -38 -29
Say the data are in file
data.txt, you can use thecolClassesargument ofread.table()to skip columns. Here the data in the first 7 columns are"integer"and we set the remaining 6 columns to"NULL"indicating they should be skippedChange
"integer"to one of the accepted types as detailed in?read.tabledepending on the real type of data.data.txtlooks like this:and was created by using
where
datisIf the number of columns is not known beforehand, the utility function
count.fieldswill read through the file and count the number of fields in each line.