[R] problem with 'which' and strings
chris.chizinski at gmail.com
Wed Feb 11 16:42:10 CET 2009
That would allocate, the vector down the column, correct? I should have
specified this clearer. I want to put each metric value into the
appropriate column (as designated by the metric name ) in a single row. My
data set SCORES.combined has the column headings for all potential metrics
that can be calculated in the database (as shown with names(orig.metric) ).
'BenInsect' CountofTaxa Darter DomTwoPct FishDELTPct
06SC048 0 10 0 7 10
whereas the next site would not necessarily have the same metrics calculated
but would have the metric values allocated into the next row based on the
David Winsemius wrote:
> Looks like you might be using vector addressing on a non-existent
> You have identified a column number, 14, to use. If you wanted to put
> the XXX.table$Metric.name vector into a column of orig.metric.scores
> (and it already existed with 10 rows), then you would would use matrix
> style addressing;
>> orig.metric.scores[,no]<- IBI.table.0$IBI.score
> David Winsemius
> On Feb 11, 2009, at 9:20 AM, Chrischizinski wrote:
>> I have written a function that goes through a database and
>> calculates various
>> metric scores and allocates them to a data set. For 400 of the 500
>> that I calculate these metrics for works fine and allocates the
>> scores into
>> the appropriate column. For some reason, some sites I run into the
>> Here is what I am doing:
>>  "BenInsect" "CountofTaxa" "Darter"
>>  "DomTwoPct" "FishDELTPct" "Minnows-
>>  "NumberPer100m-Tolerant" "Sensitive" "SLithopPct"
>>  "TolerantPct" "Omnivore" "PiscivorePct"
>>  "Headwater-Tolerant" "Insect-Tolerant" "Wetland-
>>  "Piscivore" "DarterSculpNot" "OmnivorePct"
>>  "SlithopPct"
>> For this given site the metrics that are calculated are
>>  "CountofTaxa" "DarterSculpNot" "FishDELTPct"
>>  "Insect-Tolerant" "NumberPer100m-Tolerant"
>>  "Sensitive" "SLithopPct" "TolerantPct"
>>  "Wetland-Tolerant"
>> I then try to use 'which' to determine the appropriate columns to
>> each metric into
>> no<- which(names(orig.metric)==XXX.table$Metric.name)
>> and this gives me
>>  14
>> So when I use
>> orig.metric.scores[no]<- IBI.table.0$IBI.score
>> I get this error:
>> Error in `[<-.data.frame`(`*tmp*`, no, value = c(2, 5, 10, 2, 10, 0,
>> 0, :
>> replacement has 10 rows, data has 1
>> I know why the error is being generated but I do not know why it
>> will not
>> properly identify which columns to allocate the metrics into. I
>> have tried
>> many things, including setting options(stringsAsFactors = FALSE) in my
>> Where am I going wrong here? Any suggestions or work arounds would
>> help me
>> View this message in context:
>> Sent from the R help mailing list archive at Nabble.com.
>> R-help at r-project.org mailing list
>> PLEASE do read the posting guide
>> and provide commented, minimal, self-contained, reproducible code.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
View this message in context: http://www.nabble.com/problem-with-%27which%27-and-strings-tp21955970p21957584.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help