Hello,

I'm glad it helped.

Your attachment came in corrupted. It's better to save the file as csv or tab or space separated values text file. Use write.table or write.csv to save the data. Even if there's a transmission problem, most of it will be intact, just delete a row or so.

Rui Barradas

Em 16-07-2012 15:27, Yolande Tra escreveu:
Hello,
Can I ask you another question? Attached is the file created from
as.xts. After submitting the following code, I got an error. Please
help. Thanks.

diveCond <- data.frame(matrix(0, nrow=61, ncol=17))

names(diveCond) <- c("dive_id", "timestamp", "visability", "r_wvht",
"r_dpd", "r_apt", "r_mwd", "r_wtmp", "l_salinity", "l_o2", "l_hs",
"l_tp", "l_wdir", "l_along", "l_cross", "l_mab", "l_depth")

dive_id <- 0

for(i in unique(as.character(index(diveData_2008)))){

dive_id <- dive_id+1

diveCond$dive_id[dive_id] <- dive_id

diveCond$timestamp[dive_id] <- as.character(i)

diveCond$visability[dive_id] <- as.numeric(diveData_2008[i][1,11])

}

Error in if (length(c(year, month, day, hour, min, sec)) == 6 && c(year,:

missing value where TRUE/FALSE needed

In addition: Warning messages:

1: In as_numeric(YYYY) : NAs introduced by coercion

2: In as_numeric(YYYY) : NAs introduced by coercion

Thanks,

Yolande



On Mon, Jul 16, 2012 at 2:51 AM, Rui Barradas <ruipbarra...@sapo.pt
<mailto:ruipbarra...@sapo.pt>> wrote:

    Hello,

    I can see several things that are not right or may go wrong.
    (Without an actual dataset, this is just a series of hints.)

    1. The read.csv statement. Like read.table, it creates a data.frame,
    which defaults to reading strings as factors, coded internally as
    integers. Sometimes there are problems, when using them and you are
    converting the dates/times to POSIXct. You can try to use read.csv
    option

    stringsAsFactors = FALSE

    and then do the conversions. These conversions would include
    converting 'species' and 'site' to factor, if you want them as factors.

    2. Are there typos in your posted code example?
    2.a) You read into data.frame 'd1' but then use d$date and d$TIME.
    2.b) In 'd1' the column is named 'time', not 'TIME'.

    3. Try to create the date/time and assign it to a variable, for
    instance,

    dtvar <- as.POSIXct(...etc...)

    Now you can check length(dtvar) and NROW(d1) to see if they are
    equal. You can also see if the conversion was allright. This is a
    general rule: if there's an error in a complicated instruction,
    break it into smaller ones.

    Hope this helps,

    Rui Barradas

    Em 16-07-2012 03:10, Yolande Tra escreveu:

        Hi
        I got the following error using as.xts
        Error in xts(x, order.by <http://order.by/> = order.by
        <http://order.by/>, frequency = frequency, ...) :
            NROW(x) must match length(order.by <http://order.by/>)
        Here is how the data looks like

            d1 <-
            
read.csv(file.path(dataDir,"__AppendixA-FishCountsTable-__2009.csv"),

        as.is <http://as.is/>=T)

            d1[1:3,]

            dive_id       date  time      species count size    site
        depth level
        TRANSECT VIS_M
        1      62 10/12/2009 12:44 E. lateralis     2   15 Hopkins    15
             B
             1     4
        2      62 10/12/2009 12:44 E. lateralis     1   22 Hopkins    15
             B
             1     4
        3      62 10/12/2009 12:44 E. lateralis     1   25 Hopkins    15
             B
             1     4

            diveData_2009 <- as.xts( d1,order.by
            <http://order.by/>=as.POSIXct(__strptime(paste(d$date,

        d$TIME ), "%d/%m/%Y %H:%M") ))
        Error in xts(x, order.by <http://order.by/> = order.by
        <http://order.by/>, frequency = frequency, ...) :
            NROW(x) must match length(order.by <http://order.by/>)

        I could not figure out how to correct it
        Thank you for your help
        Yolande

                 [[alternative HTML version deleted]]

        ________________________________________________
        R-help@r-project.org <mailto:R-help@r-project.org> mailing list
        https://stat.ethz.ch/mailman/__listinfo/r-help
        <https://stat.ethz.ch/mailman/listinfo/r-help>
        PLEASE do read the posting guide
        http://www.R-project.org/__posting-guide.html
        <http://www.r-project.org/posting-guide.html>
        and provide commented, minimal, self-contained, reproducible code.




______________________________________________
R-help@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.

Reply via email to