Hi, To Mason: I like your idea with reshaping the dataframe. I've read the paper and checked the help for the "cast" function, but I wasn't able to reshape it to wanted form, which as you mentioned would be (column names): jul time dtime ddawn.noon ddawn.midnight ddusk.noon ddusk.midnight
And maybe it would be easier to do with this dataframe (the basic one which later I use to create other dataframes, the one mentioned above as well), I'm not sure: > LOC[ 21:30,] jul fix dawn dusk lat long 21 14664 midnight 07:49 20:00 15.92 -25.30 22 14664 noon 07:49 19:50 24.04 -24.07 23 14665 midnight <NA> <NA> NA NA 24 14665 noon <NA> <NA> NA NA 25 14666 midnight <NA> <NA> NA NA 26 14666 noon 07:48 19:55 21.19 -24.65 27 14667 midnight 07:51 19:55 24.32 -25.05 28 14667 noon 07:51 20:00 20.43 -25.69 29 14668 midnight 07:49 20:00 19.08 -25.47 30 14668 noon 07:49 19:53 26.24 -24.61 > dput(LOC[ 21:30,]) structure(list(jul = c("14664", "14664", "14665", "14665", "14666", "14666", "14667", "14667", "14668", "14668"), fix = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("midnight", "noon" ), class = "factor"), dawn = structure(c(38L, 38L, NA, NA, NA, 37L, 40L, 40L, 38L, 38L), .Label = c("07:12", "07:13", "07:14", "07:15", "07:16", "07:17", "07:18", "07:19", "07:20", "07:21", "07:22", "07:23", "07:24", "07:25", "07:26", "07:27", "07:28", "07:29", "07:30", "07:31", "07:32", "07:33", "07:34", "07:35", "07:36", "07:37", "07:38", "07:39", "07:40", "07:41", "07:42", "07:43", "07:44", "07:45", "07:46", "07:47", "07:48", "07:49", "07:50", "07:51", "07:52", "07:53", "07:54", "07:55", "07:56", "07:57", "07:58", "07:59", "08:00", "08:01", "08:02", "08:03", "08:04", "08:05", "08:06", "08:07", "08:08", "08:11", "08:12", "08:13", "08:15", "08:16", "08:17", "08:18", "08:19", "08:20", "08:21", "08:22", "08:23", "08:25", "08:27", "08:28", "08:29", "08:30", "08:31", "08:32", "08:35", "08:41"), class = "factor"), dusk = structure(c(55L, 45L, NA, NA, NA, 50L, 50L, 55L, 55L, 48L), .Label = c("18:53", "19:00", "19:01", "19:03", "19:05", "19:07", "19:08", "19:09", "19:10", "19:12", "19:13", "19:14", "19:15", "19:16", "19:17", "19:19", "19:20", "19:21", "19:22", "19:23", "19:24", "19:25", "19:26", "19:28", "19:29", "19:30", "19:32", "19:33", "19:34", "19:35", "19:36", "19:37", "19:38", "19:39", "19:40", "19:41", "19:42", "19:43", "19:44", "19:45", "19:46", "19:47", "19:48", "19:49", "19:50", "19:51", "19:52", "19:53", "19:54", "19:55", "19:56", "19:57", "19:58", "19:59", "20:00", "20:01", "20:02", "20:03", "20:04", "20:05", "20:06", "20:07", "20:08", "20:09", "20:10", "20:11", "20:13", "20:15", "20:20", "20:25", "20:26", "20:29", "20:30", "20:31", "20:35", "20:36", "20:38", "20:40", "20:41", "20:43", "20:44", "20:45", "20:46", "20:47", "20:48", "20:49", "20:50", "20:51", "20:52", "20:54", "20:55", "20:56", "20:58", "21:00", "21:01", "21:02", "21:03", "21:04", "21:05", "21:06", "21:07", "21:08", "21:09", "21:10", "21:12", "21:13", "21:14", "21:15", "21:16", "21:17", "21:18", "21:19", "21:20", "21:21", "21:22", "21:23", "21:24", "21:25", "21:26", "21:27", "21:28", "21:30", "21:31", "21:34" ), class = "factor"), lat = c(15.92, 24.04, NA, NA, NA, 21.19, 24.32, 20.43, 19.08, 26.24), long = c(-25.3, -24.07, NA, NA, NA, -24.65, -25.05, -25.69, -25.47, -24.61)), .Names = c("jul", "fix", "dawn", "dusk", "lat", "long"), row.names = 21:30, class = "data.frame") Could you, please, help me with that? The wanted is dataframe with these columns: jul ddawn.noon ddawn.midnight ddusk.noon ddusk.midnight lat.noon lat.midnight long.noon long.midnight Thanks, Zuzana On 22 March 2013 19:44, Mason <ma...@verbasoftware.com> wrote: > It sounds like, although your "noon" and "midnight" data are separate > rows, they are not fully independent. If I understand correctly, the > operation you want to perform would be simple if you had (at least > temporarily) a single row with columns ddawn.midnight, ddusk.midnight, > ddawn.noon, ddusk.noon, rather than two separate rows. > > I recommend you check out the reshape package http://had.co.nz/reshape/, > and read the paper Hadley wrote about it for a conceptual understanding of > wide vs. long data. > > On Fri, Mar 22, 2013 at 11:18 AM, zuzana zajkova <zuzu...@gmail.com>wrote: > >> Hi, >> >> I would appreciate if somebody could help me with this small issue... >> I have a dataframe like this (originaly has more than 100 000 rows): >> >> > subz >> jul time dtime fix ddawn ddusk day >> 101608 15006 2011-02-01 19:14:49 19.24694 noon 7.916667 19.88333 1 >> 101609 15006 2011-02-01 19:24:49 19.41361 midnight 7.916667 19.56667 1 >> 101610 15006 2011-02-01 19:24:49 19.41361 noon 7.916667 19.88333 1 >> 101611 15006 2011-02-01 19:34:49 19.58028 midnight 7.916667 19.56667 0 >> 101612 15006 2011-02-01 19:34:49 19.58028 noon 7.916667 19.88333 1 >> 101613 15006 2011-02-01 19:44:49 19.74694 midnight 7.916667 19.56667 0 >> 101614 15006 2011-02-01 19:44:49 19.74694 noon 7.916667 19.88333 1 >> 101615 15006 2011-02-01 19:54:49 19.91361 midnight 7.916667 19.56667 0 >> 101616 15006 2011-02-01 19:54:49 19.91361 noon 7.916667 19.88333 0 >> 101617 15006 2011-02-01 20:04:49 20.08028 midnight 7.916667 19.56667 0 >> 101618 15006 2011-02-01 20:04:49 20.08028 noon 7.916667 19.88333 0 >> >> > dput(subz) >> structure(list(jul = c(15006, 15006, 15006, 15006, 15006, 15006, >> 15006, 15006, 15006, 15006, 15006), time = structure(c(1296587689, >> 1296588289, 1296588289, 1296588889, 1296588889, 1296589489, 1296589489, >> 1296590089, 1296590089, 1296590689, 1296590689), class = c("POSIXct", >> "POSIXt"), tzone = "GMT"), dtime = c(19.2469444444444, 19.4136111111111, >> 19.4136111111111, 19.5802777777778, 19.5802777777778, 19.7469444444444, >> 19.7469444444444, 19.9136111111111, 19.9136111111111, 20.0802777777778, >> 20.0802777777778), fix = structure(c(2L, 1L, 2L, 1L, 2L, 1L, >> 2L, 1L, 2L, 1L, 2L), .Label = c("midnight", "noon"), class = "factor"), >> ddawn = c(7.91666666666667, 7.91666666666667, 7.91666666666667, >> 7.91666666666667, 7.91666666666667, 7.91666666666667, >> 7.91666666666667, >> 7.91666666666667, 7.91666666666667, 7.91666666666667, 7.91666666666667 >> ), ddusk = c(19.8833333333333, 19.5666666666667, 19.8833333333333, >> 19.5666666666667, 19.8833333333333, 19.5666666666667, >> 19.8833333333333, >> 19.5666666666667, 19.8833333333333, 19.5666666666667, 19.8833333333333 >> ), day = c(1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0)), .Names = c("jul", >> "time", "dtime", "fix", "ddawn", "ddusk", "day"), row.names = >> 101608:101618, class = "data.frame") >> >> where "day" is calculated as >> >> subz$day <- ifelse( subz$dtime > subz$ddusk | subz$dtime < subz$ddawn, 0, >> 1 >> ) >> >> The way I would like to calculate "day" is this >> - for the same "time", the "day" is calculated for "noon" as mentioned >> above but for "midnight" is just copying the same value as for "noon". >> So for the same "time" the "day" value should be the same for "noon" and >> "midnight". >> Something like this: >> >> jul time dtime fix ddawn ddusk day >> 101608 15006 2011-02-01 19:14:49 19.24694 noon 7.916667 19.88333 1 >> 101609 15006 2011-02-01 19:24:49 19.41361 midnight 7.916667 19.56667 1 >> 101610 15006 2011-02-01 19:24:49 19.41361 noon 7.916667 19.88333 1 >> 101611 15006 2011-02-01 19:34:49 19.58028 midnight 7.916667 19.56667 1 >> 101612 15006 2011-02-01 19:34:49 19.58028 noon 7.916667 19.88333 1 >> 101613 15006 2011-02-01 19:44:49 19.74694 midnight 7.916667 19.56667 1 >> 101614 15006 2011-02-01 19:44:49 19.74694 noon 7.916667 19.88333 1 >> 101615 15006 2011-02-01 19:54:49 19.91361 midnight 7.916667 19.56667 0 >> 101616 15006 2011-02-01 19:54:49 19.91361 noon 7.916667 19.88333 0 >> 101617 15006 2011-02-01 20:04:49 20.08028 midnight 7.916667 19.56667 0 >> 101618 15006 2011-02-01 20:04:49 20.08028 noon 7.916667 19.88333 0 >> >> Where I get stuck, is I don't know how to get the value for "midnight". >> >> Any suggestion is welcome. Thanks >> >> Zuzana >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> 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. >> > > [[alternative HTML version deleted]] ______________________________________________ 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.