[R] i'm so stuck with text file and contour plot

Mark Difford mark_difford at yahoo.co.uk
Mon Aug 3 08:55:40 CEST 2009


Hi David,

>> I think he may also need to add the header=TRUE argument:

No! The argument header= is not required in this case.

##
> TDat <- read.csv("small.txt", sep="\t") 
> str(TDat[,1:3])
'data.frame':   10 obs. of  3 variables:
 $ Placename: Factor w/ 10 levels "Aankoms","Aapieshoek",..: 1 2 3 4 5 6 7 8
9 10
 $ X_coord  : num  30.9 31.4 31.1 31.4 18.7 ...
 $ Y_coord  : num  -26.2 -27.4 -29 -29 -33.5 ...

?read.csv, sub header:
"If missing, the value is determined from the file format: header is set to
TRUE if and only if the first row contains one fewer field than the number
of columns."

regards, Mark.


David Winsemius wrote:
> 
> I think he may also need to add the header=TRUE argument:
> 
> tdat <- read.csv("http://www.nabble.com/file/p24777697/small.txt",  
> header=TRUE, sep="\t")
> 
> Note: read.table with those arguments should have worked as well.
> 
> And then use names(tdat) <- c(<less bloated list of variable names>)
> 
> Perhaps along these lines:
> tdnames <- names(tdat)
> tdnames
> 
> #####------don't paste----------
> [1] "Placename"
> [2] "X_coord"
> [3] "Y_coord"
> [4] "Jan.to.Dec.2006.Stroke.Density.per.sq.km"
> [5] "Jan.to.Dec.2007.Stroke.Density.per.sq.km"
> [6] "Jan.to.Oct.2008.Stroke.Density.per.sq.km"
> [7] "Total.Strokes.per.sq.km.for.Jan.2006.to.Oct.2008"
> #######-------------
> 
>   names(tdat)[4:7] <- c("Strk.dens.2006", "Strk.dens.2007", "Strk.dens. 
> 2008", "cumStrk.2006_8")
> 
>             # cannot use variable names that begin with numbers  
> without special efforts
> tdat       # now can be displayed more economically
> 
> -- 
> David
> 
> On Aug 2, 2009, at 2:10 PM, Mark Difford wrote:
> 
>>
>> Hannes,
>>
>>>> been trying to read a text file that contains heading in the first  
>>>> line
>>>> in to R but cant.
>>
>> You want the following:
>>
>> ##
>> TDat <- read.csv("small.txt", sep="\t")
>> TDat
>> str(TDat)
>>
>> See ?read.csv
>>
>> Regards, Mark.
>>
>>
>> hannesPretorius wrote:
>>>
>>> Ok i feel pretty stupid.. been trying to read a text file that  
>>> contains
>>> heading in the first line in to R but cant. all i need to do is  
>>> make a
>>> contour plot for a friend but after weeks i feel like giving up.. i
>>> included the first few lines of the file.. any help will be great
>>>
>>> Thanks
>>>
>>> Hannes http://www.nabble.com/file/p24777697/small.txt small.txt
>>>
>>
>> -- 
>> View this message in context:
>> http://www.nabble.com/i%27m-so-stuck-with-text-file-and-contour-plot-tp24777697p24780416.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: http://www.nabble.com/i%27m-so-stuck-with-text-file-and-contour-plot-tp24777697p24786217.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list