Importing text file with many covariates

posts related to the RMark library, which may not be of general interest to users of 'classic' MARK

Importing text file with many covariates

Postby tmharms » Thu Jan 10, 2013 11:32 am

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)))
tmharms
 
Posts: 1
Joined: Tue Jan 01, 2013 12:47 pm

Re: Importing text file with many covariates

Postby tommyg » Thu Jan 10, 2013 11:57 am

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
tommyg
 
Posts: 21
Joined: Tue Mar 01, 2011 1:55 pm

Re: Importing text file with many covariates

Postby jlaake » Thu Jan 10, 2013 12:07 pm

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
jlaake
 
Posts: 1480
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA


Return to RMark

Who is online

Users browsing this forum: No registered users and 1 guest