Page 1 of 1

Importing text file with many covariates

PostPosted: Thu Jan 10, 2013 11:32 am
by tmharms
Hi All,

I am new to RMark, so I apologize if this is question is an "easy fix". I am attempting to import a tab-delimited text file that contains my capture history, frequency, and 965 individual covariates for an occupancy model. When using the "import.chdata" function without specifying field types for my covariates, the function works just fine except that all my covariates are imported as factors when they need to be numeric. Rather than typing "n" 965 times, I tried using the "rep" function to repeat "n" 965 times for the field types. However, when doing so I receive the following error:

Error in if (field.types[i - 1] == "f") data[, i] = as.factor(data[, i]) else if (field.types[i - : missing value where TRUE/FALSE needed

I can't seem to figure out why I receive this error message (and again, I apologize if it is something simple that I am overlooking). Below is the code I am using to import the data. Any assistance would be appreciated. Thanks!

test=import.chdata("test.txt",header=T,field.types=c(rep("n",965)))

Re: Importing text file with many covariates

PostPosted: Thu Jan 10, 2013 11:57 am
by tommyg
I don't use this function, but take a look at the help file on the function and the examples provided.
Code: Select all
?import.chdata

In your code, I would try
Code: Select all
test=import.chdata("test.txt",header=T,field.types="n")


If that doesn't work, you're welcome to send me the data off list and I'll take a look.

Tommy

Re: Importing text file with many covariates

PostPosted: Thu Jan 10, 2013 12:07 pm
by jlaake
import.chdata is a convenience wrapper for read.table and any of the read functions in R can be used. I constructed it because it makes sure that ch is a character string and does some other testing. If you can't work it out, you may want to look at some of the other read functions in R. All you need to do is construct at dataframe with ch as a character string and the rest is optional.

--jeff