[R] how can I convert a result (text) in table format in R?
David Winsemius
dwinsemius at comcast.net
Sun Apr 14 01:39:07 CEST 2013
On Apr 13, 2013, at 12:36 PM, David Winsemius wrote:
>
> On Apr 13, 2013, at 3:34 AM, Kristi Glover wrote:
>
>> Hi R user,
>> Could you please give me some hints on how I can convert text in table format in R?
>> I was doing model assessment using dismo package
>> for example:
>> bg <- randomPoints(current, 500)
>
> I doubt very much that 'randomPoints' is a base function. You are asked to include the names of contributed packages. Failing to do so implies that you expect us to go search for the package. I used to do so but have abandoned that action since it implicitly encourages inconsiderate behavior.
OOOPs. The package name was mentioned and it was not one I recognized and I missed it. I guess I needed to be hit over the head.
>
>> pvtest <- data.frame(extract(current, occtest))
>> avtest <- data.frame(extract(current, bg))
>> e2 = evaluate(model, p=pvtest, a=avtest)
>>> e2
>> class : ModelEvaluation
>> n presences : 10
>> n absences : 1000
>> AUC : 0.9952
>> cor : 0.6453986
>> max TPR+TNR at : 0.4496625
>>
>> I wanted to put the e2 into table. How can I change the text (e2 results) in table format?
>
> If we knew what structure the 'evaluate' function in the unnamed package was returning, we might be able to help. There is probably either an S3-print method or an S4-show method that is displaying that text but such results are not always a good guide to what is returned as the object from a function.
Running the example in dismo::evaluate
> p <- rnorm(50, mean=0.7, sd=0.3)
> # b has the predicted values for 50 background locations (or absence)
> a <- rnorm(50, mean=0.4, sd=0.4)
> e <- evaluate(p=p, a=a)
>
> e
class : ModelEvaluation
n presences : 50
n absences : 50
AUC : 0.7044
cor : 0.3595658
max TPR+TNR at : 0.4903
str(capture.output(e))
chr [1:6] "class : ModelEvaluation " "n presences : 50 " "n absences : 50 " ...
So capture.output will return a character vector with the lines of the show method for the S4 value returned by `evaluate`. If you wanted to capture that as a dataframe you could do this:
> out <- read.table(text=capture.output(e), sep=":")
> out
V1 V2
1 class ModelEvaluation
2 n presences 50
3 n absences 50
4 AUC 0.7044
5 cor 0.3595658
6 max TPR+TNR at 0.4903
Or you could extract some (but not all) of the values using "@":
e at np # returns 50
e at auc # returns 0.704
>
>> Thanks
>> Kristi
>>
>> [[alternative HTML version deleted]]
>
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list