Warning when precompiling a module which uses ParallelAccelerator - julia

Whenever I try to precompile a module which includes using ParallelAccelerator, I get the following warning,
WARNING: eval from module J2CArray to Foo:
Expr(:block, Expr(:line, 69, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, Expr(:function, Expr(:call, :j2c_array_size, Expr(:::, :arr, Expr(:curly, :Ptr, :Void)::Any)::Any, Expr(:::, :dim, :Int)::Any)::Any, Expr(:block, Expr(:line, 70, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, :l = Expr(:call, :ccall, Expr(:tuple, Expr(:quote, :j2c_array_size)::Any, "/home/miguel/.julia/v0.6/ParallelAccelerator/src/../deps/libj2carray.so.1.0")::Any, :Cuint, Expr(:tuple, Expr(:curly, :Ptr, :Void)::Any, :Cuint)::Any, :arr, Expr(:call, :convert, :Cuint, :dim)::Any)::Any, Expr(:line, 72, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, Expr(:return, Expr(:call, :convert, :Int, :l)::Any)::Any)::Any)::Any, Expr(:line, 77, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, Expr(:function, Expr(:call, :j2c_array_to_pointer, Expr(:::, :arr, Expr(:curly, :Ptr, :Void)::Any)::Any, Expr(:::, :own, :Bool)::Any)::Any, Expr(:block, Expr(:line, 78, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, Expr(:call, :ccall, Expr(:tuple, Expr(:quote, :j2c_array_to_pointer)::Any, "/home/miguel/.julia/v0.6/ParallelAccelerator/src/../deps/libj2carray.so.1.0")::Any, Expr(:curly, :Ptr, :Void)::Any, Expr(:tuple, Expr(:curly, :Ptr, :Void)::Any, :Bool)::Any, :arr, :own)::Any)::Any)::Any, Expr(:line, 84, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, Expr(:function, Expr(:call, :j2c_array_get, Expr(:::, :arr, Expr(:curly, :Ptr, :Void)::Any)::Any, Expr(:::, :idx, :Int)::Any, Expr(:::, :T, :Type)::Any)::Any, Expr(:block, Expr(:line, 85, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, :nbytes = Expr(:if, Expr(:call, :===, :T, Expr(:curly, :Ptr, :Void)::Any)::Any, 0, Expr(:call, :sizeof, :T)::Any)::Any, Expr(:line, 86, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, :_value = Expr(:call, Expr(:curly, :Array, :T)::Any, 1)::Any, Expr(:line, 87, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, Expr(:call, :ccall, Expr(:tuple, Expr(:quote, :j2c_array_get)::Any, "/home/miguel/.julia/v0.6/ParallelAccelerator/src/../deps/libj2carray.so.1.0")::Any, :Void, Expr(:tuple, :Cint, Expr(:curly, :Ptr, :Void)::Any, :Cuint, Expr(:curly, :Ptr, :Void)::Any)::Any, Expr(:call, :convert, :Cint, :nbytes)::Any, :arr, Expr(:call, :convert, :Cuint, :idx)::Any, Expr(:call, :convert, Expr(:curly, :Ptr, :Void)::Any, Expr(:call, :pointer, :_value)::Any)::Any)::Any, Expr(:line, 89, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, Expr(:return, Expr(:ref, :_value, 1)::Any)::Any)::Any)::Any, Expr(:line, 94, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, Expr(:function, Expr(:call, Expr(:curly, :j2c_array_set, :T)::Any, Expr(:::, :arr, Expr(:curly, :Ptr, :Void)::Any)::Any, Expr(:::, :idx, :Int)::Any, Expr(:::, :value, :T)::Any)::Any, Expr(:block, Expr(:line, 95, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, :nbytes = Expr(:if, Expr(:call, :===, :T, Expr(:curly, :Ptr, :Void)::Any)::Any, 0, Expr(:call, :sizeof, :T)::Any)::Any, Expr(:line, 96, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, :_value = Expr(:if, Expr(:call, :==, :nbytes, 0)::Any, :value, Expr(:call, :convert, Expr(:curly, :Ptr, :Void)::Any, Expr(:call, :pointer, Expr(:ref, :T, :value)::Any)::Any)::Any)::Any, Expr(:line, 97, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, Expr(:call, :ccall, Expr(:tuple, Expr(:quote, :j2c_array_set)::Any, "/home/miguel/.julia/v0.6/ParallelAccelerator/src/../deps/libj2carray.so.1.0")::Any, :Void, Expr(:tuple, :Cint, Expr(:curly, :Ptr, :Void)::Any, :Cuint, Expr(:curly, :Ptr, :Void)::Any)::Any, Expr(:call, :convert, :Cint, :nbytes)::Any, :arr, Expr(:call, :convert, :Cuint, :idx)::Any, :_value)::Any)::Any)::Any, Expr(:line, 107, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, Expr(:function, Expr(:call, :j2c_array_delete, Expr(:::, :arr, Expr(:curly, :Ptr, :Void)::Any)::Any)::Any, Expr(:block, Expr(:line, 108, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, Expr(:call, :ccall, Expr(:tuple, Expr(:quote, :j2c_array_delete)::Any, "/home/miguel/.julia/v0.6/ParallelAccelerator/src/../deps/libj2carray.so.1.0")::Any, :Void, Expr(:tuple, Expr(:curly, :Ptr, :Void)::Any)::Any, :arr)::Any)::Any)::Any, Expr(:line, 115, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, Expr(:function, Expr(:call, :j2c_array_deref, Expr(:::, :arr, Expr(:curly, :Ptr, :Void)::Any)::Any)::Any, Expr(:block, Expr(:line, 116, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, Expr(:call, :ccall, Expr(:tuple, Expr(:quote, :j2c_array_deref)::Any, "/home/miguel/.julia/v0.6/ParallelAccelerator/src/../deps/libj2carray.so.1.0")::Any, :Void, Expr(:tuple, Expr(:curly, :Ptr, :Void)::Any)::Any, :arr)::Any)::Any)::Any, Expr(:line, 119, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, Expr(:if, Expr(:call, :>=, :VERSION, Expr(:macrocall, :#v_str, "0.6.0-pre")::Any)::Any, Expr(:block, Expr(:line, 121, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, Expr(:function, Expr(:call, :to_j2c_array, Expr(:::, :inp, :AbstractString)::Any, :ptr_array_dict, :mapAtypeKey, :j2c_array_new)::Any, Expr(:block, Expr(:line, 122, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, :arr = Expr(:call, :to_j2c_array, Expr(:call, Expr(:curly, :Vector, :UInt8)::Any, :inp)::Any, :ptr_array_dict, :mapAtypeKey, :j2c_array_new)::Any, Expr(:line, 123, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, Expr(:call, :ccall, Expr(:tuple, Expr(:quote, :new_ascii_string)::Any, "/home/miguel/.julia/v0.6/ParallelAccelerator/src/../deps/libj2carray.so.1.0")::Any, Expr(:curly, :Ptr, :Void)::Any, Expr(:tuple, Expr(:curly, :Ptr, :Void)::Any)::Any, :arr)::Any)::Any)::Any)::Any, Expr(:block, Expr(:line, 127, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, Expr(:function, Expr(:call, :to_j2c_array, Expr(:::, :inp, :AbstractString)::Any, :ptr_array_dict, :mapAtypeKey, :j2c_array_new)::Any, Expr(:block, Expr(:line, 128, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, :arr = Expr(:call, :to_j2c_array, Expr(:., :inp, :data)::Any, :ptr_array_dict, :mapAtypeKey, :j2c_array_new)::Any, Expr(:line, 129, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, Expr(:call, :ccall, Expr(:tuple, Expr(:quote, :new_ascii_string)::Any, "/home/miguel/.julia/v0.6/ParallelAccelerator/src/../deps/libj2carray.so.1.0")::Any, Expr(:curly, :Ptr, :Void)::Any, Expr(:tuple, Expr(:curly, :Ptr, :Void)::Any)::Any, :arr)::Any)::Any)::Any)::Any)::Any, Expr(:line, 134, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, Expr(:function, Expr(:call, :from_ascii_string, Expr(:::, :str, Expr(:curly, :Ptr, :Void)::Any)::Any, :ptr_array_dict)::Any, Expr(:block, Expr(:line, 135, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, :data = Expr(:call, :ccall, Expr(:tuple, Expr(:quote, :from_ascii_string)::Any, "/home/miguel/.julia/v0.6/ParallelAccelerator/src/../deps/libj2carray.so.1.0")::Any, Expr(:curly, :Ptr, :Void)::Any, Expr(:tuple, Expr(:curly, :Ptr, :Void)::Any)::Any, :str)::Any, Expr(:line, 136, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, :arr = Expr(:call, :_from_j2c_array, :data, :UInt8, 1, :ptr_array_dict)::Any, Expr(:line, 137, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, Expr(:call, :ccall, Expr(:tuple, Expr(:quote, :delete_ascii_string)::Any, "/home/miguel/.julia/v0.6/ParallelAccelerator/src/../deps/libj2carray.so.1.0")::Any, :Void, Expr(:tuple, Expr(:curly, :Ptr, :Void)::Any)::Any, :str)::Any, Expr(:line, 138, Symbol("/home/miguel/.julia/v0.6/ParallelAccelerator/src/j2c-array.jl"))::Any, Expr(:return, :arr)::Any)::Any)::Any)::Any
** incremental compilation may be broken for this module **
I can reproduce this warning with 5 lines of code. First I create the module:
Foo.jl
__precompile__()
module Foo
using ParallelAccelerator
end
then I create a test script:
test.jl
using Foo
Finally I run the test script with Julia 0.6.4
$ julia test.jl
Is this a problem with ParallelAccelerator or the setup of my system?

Related

How to reorder day of year so that seasons line up

I am working with seasonal data in Australia that spans from their Spring to Fall. I would like to have a column with day of year. However, when I use the yday function from the lubridate, I receive a distribution like this:
The issue here is that the Australian summer (peak time for data collection) goes through the new year. If I tried to add this variable into the model, it would produce incorrect results.
So my question is:
How can I get a seasonally appropriate 'day of year' column for this dataset
I have included some data here:
structure(list(Date = structure(c(11323, 11323, 11323, 11323,
12784, 11324, 12785, 11324, 12419, 12785, 12786, 12786, 13151,
13151, 13151, 12787, 12421, 15343, 15709, 12787, 14614, 15344,
11327, 15344, 14614, 13154, 15711, 15711, 11328, 13154, 16442,
15712, 15712, 16442, 16442, 13886, 16443, 16443, 16443, 16443,
16444, 16444, 13887, 13157, 13157, 13158, 13158, 11697, 16445,
13158, 13889, 16446, 11698, 15716, 11333, 16447, 13525, 13525,
13160, 15351, 11335, 12430, 14257, 13161, 12796, 13162, 12066,
13162, 13892, 13162, 13893, 16085, 14989, 16815, 16085, 16086,
13164, 16086, 17182, 13894, 17183, 15356, 17183, 13165, 11704,
14992, 13166, 14262, 17184, 12435, 11706, 17185, 14628, 14993,
14628, 14629, 14629, 14994, 13168, 16455, 16456, 12804, 16456,
16456, 13899, 12805, 14996, 14996, 16822, 16457, 13171, 16458,
14997, 12806, 14997, 14998, 13172, 13172, 13172, 14998, 13173,
13173, 12808, 12808, 13173, 17192, 13904, 13174, 13174, 13174,
14271, 13175, 13175, 15001, 17193, 12445, 17194, 13176, 12445,
14272, 16464, 16464, 15734, 13907, 14638, 14639, 13178, 13178,
16465, 14639, 16466, 13179, 13179, 16101, 13179, 13910, 12449,
16467, 13910, 16467, 13181, 15372, 13181, 14277, 16468, 14278,
13182, 14278, 12451, 16469, 16470, 13183, 14279, 16835, 14644,
15010, 13549, 14645, 12819, 12819, 17203, 17203, 12454, 12820,
17203, 12821, 15012, 13916, 13916, 12821, 13917, 15013, 15013,
13187, 13917, 13918, 13553, 17206, 14284, 12457, 16476, 14285,
15380, 14285, 16476, 12825, 12459, 12459, 13920, 16477, 13921,
12460, 16478, 12460, 14287, 16114, 14288, 16844, 11731, 16479,
16480, 11367, 11367, 11367, 16845, 16481, 16481, 16846, 16846,
12829, 12830, 11003, 16482, 13925, 11369, 12465, 16483, 16483,
16483, 14657, 17215, 11371, 14658, 16484, 16484, 17216, 16485,
12467, 16850, 11737, 14295, 12834, 12468, 14295, 16851, 13200,
13200, 16487, 11374, 15026, 11375, 16488, 16488, 12836, 16488,
11376, 14663, 13202, 14663, 14663, 14664, 11742, 15029, 11377,
13203, 16491, 16491, 16491, 13569, 13204, 13205, 14301, 11744,
16492, 13935, 16493, 11380, 16493, 11014, 13936, 16494, 13937,
13937, 13572, 16494, 13208, 11382, 13938, 11016, 13208, 11748,
14670, 16496, 14670, 14670, 11384, 14671, 14306, 14671, 12479,
14672, 16498, 16498, 14672, 14672, 14673, 13942, 12481, 13942,
12481, 14309, 16500, 12482, 13943, 13943, 12849, 12483, 15771,
13944, 16501, 16867, 16502, 13945, 12484, 15406, 17234, 16868,
11024, 16503, 17234, 17235, 17235, 17235, 17235, 16869, 17236,
13948, 13948, 13948, 17236, 15045, 15410, 13949, 16141, 13219,
15046, 12489, 15411, 13950, 13950, 11395, 11395, 11395, 12856,
11395, 15779, 15048, 16874, 12857, 16874, 16875, 16510, 16510,
15049, 15049, 14685, 12859, 16511, 15050, 16146, 16512, 14686,
12860, 12860, 12860, 16513, 16878, 14322, 12861, 11400, 15784,
16514, 15784, 13227, 12862, 16515, 12497, 16515, 16515, 14689,
13594, 14690, 12498, 12864, 12864, 11404, 13595, 11404, 12865,
12499, 12500, 12866, 14327, 16518, 16518, 14693, 14328, 14693,
16519, 16519, 12502, 16520, 14329, 14329, 14329, 12503, 11042,
16521, 11042, 13234, 11409, 12504, 14331, 12504, 12504, 15427,
15427, 13601, 15427, 11775, 13602, 16889, 17255, 12506, 12506,
16160, 12873, 15429, 14334, 12507, 12508, 12508, 11047, 13969,
12508, 13970, 11414, 14336, 13605, 13970, 12876, 17259, 16893,
16163, 13606, 13972, 16894, 16894, 11416, 13607, 13973, 12878,
13243, 11417, 13973, 17262, 12513, 13974, 12513, 12513, 16897,
12514, 12514, 16897, 11419, 13976, 16898, 16898, 13976, 16898,
16169, 12151, 15804, 11421, 16899, 16170, 16535, 12883, 16170,
16535, 11057, 11057, 16171, 13979, 16171, 13980, 13250, 14711,
16537, 13980, 14712, 13981, 15808, 13981, 14712, 14713, 14713,
14713, 16174, 14713, 16905, 15444, 16905, 14349, 14349, 13619,
14715, 12523, 16906, 14350, 14716, 13620, 15446, 12524, 12524,
13621, 13621, 13621, 14352, 12525, 12526, 12526, 12526, 12526,
14718, 12527, 11066, 16910, 12527, 13623, 16911, 12528, 16911,
14720, 16911, 14721, 12529, 13990, 11068, 13990, 14357, 12530,
14722, 14357, 13626, 13627, 12531, 13627, 13992, 13992, 11071,
13993, 11071, 11071, 14359, 13994, 11072, 13994, 14360, 13994,
14361, 11073, 14361, 14361, 14361, 16188, 16188, 14362, 14362,
14362, 11075, 13997, 14363, 14363, 14363, 14364, 16190, 14364,
16190, 16190, 14365, 16191, 16191, 11808, 16191, 14366, 14366,
16192, 11078, 14366, 16193, 16193, 16193, 16193, 16193, 16194,
16194, 16194, 16194, 16194, 12542, 16195, 16195, 12542, 12542,
12543, 12543, 12543, 12543, 16196, 14005, 14371, 16197, 14005,
14005, 12545, 14006, 12545, 14006, 12545, 14007, 14007, 12546,
12546, 12546, 14739, 14008, 12547, 12547, 14008, 14009, 14009,
14740, 12548, 15470, 14741, 14741, 15471, 14741, 14741, 14742,
14742, 14742, 16203, 14742, 14743, 14743, 14743, 14743, 14743,
16205, 16205, 13283, 16205, 16205, 16206, 13284, 13284, 16206,
13284, 16207, 16207, 16207, 16207, 15476, 15477, 15477, 15477,
15477, 15477, 15478, 15478, 15478, 14748, 15478, 15479, 14749,
11827, 14749, 14749, 11828, 11828, 14750, 11828, 14750, 16943,
16943, 16943, 16943, 16943, 11100, 11100, 11100, 11100, 11100,
16945, 16945, 16945, 16945, 16945, 16946, 16946, 16946, 16946,
16946, 16947, 16947, 16947, 16947, 16947, 16948, 16948, 16948,
16948, 16948, 16949, 16949, 16949, 16949, 16949, 16314, 16314,
14853, 16314, 16314, 16315, 16315, 14489, 14489, 14489, 16316,
16316, 16316, 14855, 14490, 16317, 13760, 16317, 16317, 16317,
16318, 16318, 13761, 14126, 13761, 13762, 15223, 13762, 16319,
16319, 12667, 14859, 14859, 17050, 12667, 16321, 11207, 11207,
11207, 11207, 11208, 11208, 14496, 13400, 13400, 16323, 14497,
16323, 13401, 14497, 14498, 16324, 14498, 16324, 13402, 16325,
15229, 11211, 15229, 13403, 15230, 15230, 15961, 17056, 15230,
14866, 15231, 13040, 15231, 15962, 13771, 14867, 14502, 15963,
11580, 14868, 14868, 15233, 16694, 16694, 15965, 14869, 15965,
13043, 14504, 14139, 16696, 12678, 14505, 15966, 14871, 13045,
16697, 16697, 14140, 14872, 11219, 11219, 14872, 13411, 13412,
11220, 15969, 14873, 14873, 14509, 14874, 14509, 14874, 12682,
14875, 12683, 14875, 14875, 14875, 12684, 11223, 14511, 14511,
14876, 14877, 12685, 14877, 14877, 12685, 12686, 16339, 14878,
14147, 14878, 16340, 14879, 14879, 14879, 14879, 11227, 11227,
14880, 14880, 14880, 14881, 14881, 16342, 14881, 14881, 16343,
14882, 14882, 14882, 14882, 11230, 14883, 12691, 14883, 12691,
16345, 14153, 16710, 14884, 14884, 14154, 15615, 14885, 12693,
11232, 14886, 14155, 14155, 14886, 14886, 14887, 14887, 14887,
14887, 14887, 14888, 14888, 14888, 12696, 14523, 14889, 16350,
14889, 15619, 14889, 14890, 14525, 14890, 14525, 14525, 14526,
14891, 14891, 14891, 14526, 14892, 14892, 16353, 16353, 12335,
14893, 14893, 14893, 14893, 14893, 13798, 17085, 14894, 17085,
13068, 14895, 13069, 14895, 14895, 14895, 17087, 14896, 17087,
14896, 12339, 17088, 16358, 16358, 14532, 16358, 14898, 12706,
14898, 14898, 14898, 16360, 14899, 14899, 11246, 14899, 14900,
12708, 14900, 14900, 14900, 14901, 14901, 14901, 16362, 14901,
14902, 14902, 14902, 14537, 14902, 14903, 14903, 14903, 14903,
12711, 14904, 12712, 14904, 12712, 14904, 15635, 14905, 11252,
14905, 11252, 14906, 14906, 12349, 14906, 14906, 14542, 14907,
14542, 14542, 16368, 16369, 14908, 14908, 14177, 16369, 16370,
14909, 14909, 12352, 16370, 14910, 17101, 14910, 14545, 14910,
14911, 11258, 16737, 12719, 14911, 16373, 16373, 14912, 14912,
12720, 14913, 14913, 14913, 14913, 11260, 14914, 16375, 11992,
11627, 14914, 14915, 14915, 14915, 14550, 15280, 14916, 13820,
14551, 14916, 14916, 14917, 14917, 14917, 14917, 14917, 11265,
14553, 16014, 14918, 12726, 11266, 14919, 11266, 16380, 14919,
14920, 12728, 12363, 12363, 14920, 14921, 14921, 17112, 14921,
14921, 14922, 14922, 14922, 11269, 14922, 14923, 14923, 14923,
16384, 14923, 14924, 16385, 14924, 14924, 11271, 16386, 14194,
14925, 16386, 14925, 14926, 16387, 13465, 14926, 11273, 11640,
12005, 14196, 14927, 14196, 14197, 12736, 14928, 14928, 14928,
12737, 13833, 14929, 14929, 11642, 14930, 14930, 14930, 14930,
14930, 17122, 12739, 13470, 13470, 12374, 14932, 12375, 14932,
13471, 13471, 11280, 14933, 14933, 14933, 14202, 14934, 14934,
14203, 14934, 14934, 14204, 14935, 14935, 14935, 14935, 12744,
14936, 14936, 14936, 14936, 16398, 11284, 16398, 16398, 16398,
11285, 14938, 16764, 14938, 12381, 16400, 16400, 12747, 12382,
14208, 14209, 11287, 14209, 16401, 13844, 16402, 15671, 14210,
16402, 12749, 12750, 13846, 16403, 16403, 14211, 15673, 15673,
16404, 11656, 16404, 17135, 17135, 16405, 16405, 17135, 14580,
16771, 12753, 12388, 14580, 13485, 17137, 14581, 14581, 12389,
16773, 16773, 15677, 13486, 11294, 12391, 16044, 14217, 14217,
13122, 12757, 13853, 14218, 17140, 14949, 16776, 17141, 17141,
16046, 14950, 15681, 12759, 15681, 16412, 12759, 14587, 13126,
13126, 16413, 16413, 16414, 16414, 16414, 13492, 16414, 16415,
15684, 16415, 16415, 16415, 16416, 14224, 16416, 14224, 14590,
14591, 14956, 12764, 14591, 16052, 14957, 12400, 11304, 11304,
12765, 14958, 14593, 11305, 16784, 14958, 12402, 12402, 12402,
12402, 12767, 14960, 14595, 14595, 13134, 16421, 12769, 12404,
12769, 14230, 14961, 12770, 12770, 12770, 15327, 12770, 14232,
14963, 12406, 17154, 14232, 17155, 14233, 14233, 17155, 17155,
17156, 17156, 14234, 17156, 12408, 12774, 17157, 12774, 17157,
17157, 11314, 12775, 17158, 12775, 12775, 11315, 11315, 11315,
11315, 11315, 11684, 11684, 13510, 11684, 11684, 13511, 13511,
13511, 11319, 11685, 11320, 12781, 11320, 13512, 12781, 11321,
11321, 11321, 11321, 11321, 11322, 11322, 11322, 11322, 11322
), class = "Date"), DOY = c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3,
3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7,
7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11,
11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 14, 14,
14, 14, 14, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 17, 17, 17,
17, 17, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 20, 20, 20, 20,
20, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23,
24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 27,
27, 27, 27, 27, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 30, 30,
30, 30, 30, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 33, 33, 33,
33, 33, 34, 34, 34, 34, 34, 35, 35, 35, 35, 35, 36, 36, 36, 36,
36, 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 39, 39, 39, 39, 39,
40, 40, 40, 40, 40, 41, 41, 41, 41, 41, 42, 42, 42, 42, 42, 43,
43, 43, 43, 43, 44, 44, 44, 44, 44, 45, 45, 45, 45, 45, 46, 46,
46, 46, 46, 47, 47, 47, 47, 47, 48, 48, 48, 48, 48, 49, 49, 49,
49, 49, 50, 50, 50, 50, 50, 51, 51, 51, 51, 51, 52, 52, 52, 52,
52, 53, 53, 53, 53, 53, 54, 54, 54, 54, 54, 55, 55, 55, 55, 55,
56, 56, 56, 56, 56, 57, 57, 57, 57, 57, 58, 58, 58, 58, 58, 59,
59, 59, 59, 59, 60, 60, 60, 60, 60, 61, 61, 61, 61, 61, 62, 62,
62, 62, 62, 63, 63, 63, 63, 63, 64, 64, 64, 64, 64, 65, 65, 65,
65, 65, 66, 66, 66, 66, 66, 67, 67, 67, 67, 67, 68, 68, 68, 68,
68, 69, 69, 69, 69, 69, 70, 70, 70, 70, 70, 71, 71, 71, 71, 71,
72, 72, 72, 72, 72, 73, 73, 73, 73, 73, 74, 74, 74, 74, 74, 75,
75, 75, 75, 75, 76, 76, 76, 76, 76, 77, 77, 77, 77, 77, 78, 78,
78, 78, 78, 79, 79, 79, 79, 79, 80, 80, 80, 80, 80, 81, 81, 81,
81, 81, 82, 82, 82, 82, 82, 83, 83, 83, 83, 83, 84, 84, 84, 84,
84, 85, 85, 85, 85, 85, 86, 86, 86, 86, 86, 87, 87, 87, 87, 87,
88, 88, 88, 88, 88, 89, 89, 89, 89, 89, 90, 90, 90, 90, 90, 91,
91, 91, 91, 91, 92, 92, 92, 92, 92, 93, 93, 93, 93, 93, 94, 94,
94, 94, 94, 95, 95, 95, 95, 95, 96, 96, 96, 96, 96, 97, 97, 97,
97, 97, 98, 98, 98, 98, 98, 99, 99, 99, 99, 99, 100, 100, 100,
100, 100, 101, 101, 101, 101, 101, 102, 102, 102, 102, 102, 103,
103, 103, 103, 103, 104, 104, 104, 104, 104, 105, 105, 105, 105,
105, 106, 106, 106, 106, 106, 107, 107, 107, 107, 107, 108, 108,
108, 108, 108, 109, 109, 109, 109, 109, 110, 110, 110, 110, 110,
111, 111, 111, 111, 111, 112, 112, 112, 112, 112, 113, 113, 113,
113, 113, 114, 114, 114, 114, 114, 115, 115, 115, 115, 115, 116,
116, 116, 116, 116, 117, 117, 117, 117, 117, 118, 118, 118, 118,
118, 119, 119, 119, 119, 119, 120, 120, 120, 120, 120, 121, 121,
121, 121, 121, 122, 122, 122, 122, 122, 123, 123, 123, 123, 123,
124, 124, 124, 124, 124, 125, 125, 125, 125, 125, 126, 126, 126,
126, 126, 127, 127, 127, 127, 127, 128, 128, 128, 128, 128, 129,
129, 129, 129, 129, 130, 130, 130, 130, 130, 131, 131, 131, 131,
131, 132, 132, 132, 132, 132, 133, 133, 133, 133, 133, 134, 134,
134, 134, 134, 135, 135, 135, 135, 135, 136, 136, 136, 136, 136,
137, 137, 137, 137, 137, 138, 138, 138, 138, 138, 139, 139, 139,
139, 139, 140, 140, 140, 140, 140, 141, 141, 141, 141, 141, 143,
143, 143, 143, 143, 144, 144, 144, 144, 144, 145, 145, 145, 145,
145, 146, 146, 146, 146, 146, 147, 147, 147, 147, 147, 148, 148,
148, 148, 148, 149, 149, 149, 149, 149, 244, 244, 244, 244, 244,
245, 245, 245, 245, 245, 246, 246, 246, 246, 246, 247, 247, 247,
247, 247, 248, 248, 248, 248, 248, 249, 249, 249, 249, 249, 250,
250, 250, 250, 250, 251, 251, 251, 251, 251, 252, 252, 252, 252,
252, 253, 253, 253, 253, 253, 254, 254, 254, 254, 254, 255, 255,
255, 255, 255, 256, 256, 256, 256, 256, 257, 257, 257, 257, 257,
258, 258, 258, 258, 258, 259, 259, 259, 259, 259, 260, 260, 260,
260, 260, 261, 261, 261, 261, 261, 262, 262, 262, 262, 262, 263,
263, 263, 263, 263, 264, 264, 264, 264, 264, 265, 265, 265, 265,
265, 266, 266, 266, 266, 266, 267, 267, 267, 267, 267, 268, 268,
268, 268, 268, 269, 269, 269, 269, 269, 270, 270, 270, 270, 270,
271, 271, 271, 271, 271, 272, 272, 272, 272, 272, 273, 273, 273,
273, 273, 274, 274, 274, 274, 274, 275, 275, 275, 275, 275, 276,
276, 276, 276, 276, 277, 277, 277, 277, 277, 278, 278, 278, 278,
278, 279, 279, 279, 279, 279, 280, 280, 280, 280, 280, 281, 281,
281, 281, 281, 282, 282, 282, 282, 282, 283, 283, 283, 283, 283,
284, 284, 284, 284, 284, 285, 285, 285, 285, 285, 286, 286, 286,
286, 286, 287, 287, 287, 287, 287, 288, 288, 288, 288, 288, 289,
289, 289, 289, 289, 290, 290, 290, 290, 290, 291, 291, 291, 291,
291, 292, 292, 292, 292, 292, 293, 293, 293, 293, 293, 294, 294,
294, 294, 294, 295, 295, 295, 295, 295, 296, 296, 296, 296, 296,
297, 297, 297, 297, 297, 298, 298, 298, 298, 298, 299, 299, 299,
299, 299, 300, 300, 300, 300, 300, 301, 301, 301, 301, 301, 302,
302, 302, 302, 302, 303, 303, 303, 303, 303, 304, 304, 304, 304,
304, 305, 305, 305, 305, 305, 306, 306, 306, 306, 306, 307, 307,
307, 307, 307, 308, 308, 308, 308, 308, 309, 309, 309, 309, 309,
310, 310, 310, 310, 310, 311, 311, 311, 311, 311, 312, 312, 312,
312, 312, 313, 313, 313, 313, 313, 314, 314, 314, 314, 314, 315,
315, 315, 315, 315, 316, 316, 316, 316, 316, 317, 317, 317, 317,
317, 318, 318, 318, 318, 318, 319, 319, 319, 319, 319, 320, 320,
320, 320, 320, 321, 321, 321, 321, 321, 322, 322, 322, 322, 322,
323, 323, 323, 323, 323, 324, 324, 324, 324, 324, 325, 325, 325,
325, 325, 326, 326, 326, 326, 326, 327, 327, 327, 327, 327, 328,
328, 328, 328, 328, 329, 329, 329, 329, 329, 330, 330, 330, 330,
330, 331, 331, 331, 331, 331, 332, 332, 332, 332, 332, 333, 333,
333, 333, 333, 334, 334, 334, 334, 334, 335, 335, 335, 335, 335,
336, 336, 336, 336, 336, 337, 337, 337, 337, 337, 338, 338, 338,
338, 338, 339, 339, 339, 339, 339, 340, 340, 340, 340, 340, 341,
341, 341, 341, 341, 342, 342, 342, 342, 342, 343, 343, 343, 343,
343, 344, 344, 344, 344, 344, 345, 345, 345, 345, 345, 346, 346,
346, 346, 346, 347, 347, 347, 347, 347, 348, 348, 348, 348, 348,
349, 349, 349, 349, 349, 350, 350, 350, 350, 350, 351, 351, 351,
351, 351, 352, 352, 352, 352, 352, 353, 353, 353, 353, 353, 354,
354, 354, 354, 354, 355, 355, 355, 355, 355, 356, 356, 356, 356,
356, 357, 357, 357, 357, 357, 358, 358, 358, 358, 358, 359, 359,
359, 359, 359, 362, 362, 362, 362, 362, 363, 363, 363, 363, 363,
364, 364, 364, 364, 364, 365, 365, 365, 365, 365, 366, 366, 366,
366, 366)), row.names = c(NA, -1345L), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"), groups = structure(list(DOY = c(1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125,
126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138,
139, 140, 141, 143, 144, 145, 146, 147, 148, 149, 244, 245, 246,
247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259,
260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272,
273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285,
286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298,
299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311,
312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324,
325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337,
338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350,
351, 352, 353, 354, 355, 356, 357, 358, 359, 362, 363, 364, 365,
366), .rows = list(1:5, 6:10, 11:15, 16:20, 21:25, 26:30, 31:35,
36:40, 41:45, 46:50, 51:55, 56:60, 61:65, 66:70, 71:75, 76:80,
81:85, 86:90, 91:95, 96:100, 101:105, 106:110, 111:115, 116:120,
121:125, 126:130, 131:135, 136:140, 141:145, 146:150, 151:155,
156:160, 161:165, 166:170, 171:175, 176:180, 181:185, 186:190,
191:195, 196:200, 201:205, 206:210, 211:215, 216:220, 221:225,
226:230, 231:235, 236:240, 241:245, 246:250, 251:255, 256:260,
261:265, 266:270, 271:275, 276:280, 281:285, 286:290, 291:295,
296:300, 301:305, 306:310, 311:315, 316:320, 321:325, 326:330,
331:335, 336:340, 341:345, 346:350, 351:355, 356:360, 361:365,
366:370, 371:375, 376:380, 381:385, 386:390, 391:395, 396:400,
401:405, 406:410, 411:415, 416:420, 421:425, 426:430, 431:435,
436:440, 441:445, 446:450, 451:455, 456:460, 461:465, 466:470,
471:475, 476:480, 481:485, 486:490, 491:495, 496:500, 501:505,
506:510, 511:515, 516:520, 521:525, 526:530, 531:535, 536:540,
541:545, 546:550, 551:555, 556:560, 561:565, 566:570, 571:575,
576:580, 581:585, 586:590, 591:595, 596:600, 601:605, 606:610,
611:615, 616:620, 621:625, 626:630, 631:635, 636:640, 641:645,
646:650, 651:655, 656:660, 661:665, 666:670, 671:675, 676:680,
681:685, 686:690, 691:695, 696:700, 701:705, 706:710, 711:715,
716:720, 721:725, 726:730, 731:735, 736:740, 741:745, 746:750,
751:755, 756:760, 761:765, 766:770, 771:775, 776:780, 781:785,
786:790, 791:795, 796:800, 801:805, 806:810, 811:815, 816:820,
821:825, 826:830, 831:835, 836:840, 841:845, 846:850, 851:855,
856:860, 861:865, 866:870, 871:875, 876:880, 881:885, 886:890,
891:895, 896:900, 901:905, 906:910, 911:915, 916:920, 921:925,
926:930, 931:935, 936:940, 941:945, 946:950, 951:955, 956:960,
961:965, 966:970, 971:975, 976:980, 981:985, 986:990, 991:995,
996:1000, 1001:1005, 1006:1010, 1011:1015, 1016:1020, 1021:1025,
1026:1030, 1031:1035, 1036:1040, 1041:1045, 1046:1050, 1051:1055,
1056:1060, 1061:1065, 1066:1070, 1071:1075, 1076:1080, 1081:1085,
1086:1090, 1091:1095, 1096:1100, 1101:1105, 1106:1110, 1111:1115,
1116:1120, 1121:1125, 1126:1130, 1131:1135, 1136:1140, 1141:1145,
1146:1150, 1151:1155, 1156:1160, 1161:1165, 1166:1170, 1171:1175,
1176:1180, 1181:1185, 1186:1190, 1191:1195, 1196:1200, 1201:1205,
1206:1210, 1211:1215, 1216:1220, 1221:1225, 1226:1230, 1231:1235,
1236:1240, 1241:1245, 1246:1250, 1251:1255, 1256:1260, 1261:1265,
1266:1270, 1271:1275, 1276:1280, 1281:1285, 1286:1290, 1291:1295,
1296:1300, 1301:1305, 1306:1310, 1311:1315, 1316:1320, 1321:1325,
1326:1330, 1331:1335, 1336:1340, 1341:1345)), row.names = c(NA,
-269L), class = c("tbl_df", "tbl", "data.frame"), .drop = TRUE))
The sample data you gave was not very illustrative, since it contained one instance each of the same day each year. We'll create some data that is perhaps more representative:
library(ggplot2)
set.seed(69)
dates <- as.Date("2015-01-01") +
lubridate::days(round(rnorm(5000, 0, 30))) +
lubridate::years(sample(0:5, 5000, TRUE))
df <- data.frame(Date = dates, DOY = lubridate::yday(dates))
ggplot(df, aes(DOY)) + geom_histogram(binwidth = 1)
The way to get rid of this gap is simply to add 6 months and take the result modulo 366:
ggplot(df, aes((DOY + 183) %% 366)) +
geom_histogram(binwidth = 1) +
lims(x = c(0, 366)) +
labs(x = "DOY")
Created on 2020-08-02 by the reprex package (v0.3.0)

How to add a variable in a data frame using another variable for indices?

Data
I have a data frame "veh" with a variable "Tim":
> dput(veh$Tim)
c(169.7, 169.8, 169.9, 170, 170.1, 170.2, 170.3, 170.4, 170.5,
170.6, 170.7, 170.8, 170.9, 171, 171.1, 171.2, 171.3, 171.4,
171.5, 171.6, 171.7, 171.8, 171.9, 172, 172.1, 172.2, 172.3,
172.4, 172.5, 172.6, 172.7, 172.8, 172.9, 173, 173.1, 173.2,
173.3, 173.4, 173.5, 173.6, 173.7, 173.8, 173.9, 174, 174.1,
174.2, 174.3, 174.4, 174.5, 174.6, 174.7, 174.8, 174.9, 175,
175.1, 175.2, 175.3, 175.4, 175.5, 175.6, 175.7, 175.8, 175.9,
176, 176.1, 176.2, 176.3, 176.4, 176.5, 176.6, 176.7, 176.8,
176.9, 177, 177.1, 177.2, 177.3, 177.4, 177.5, 177.6, 177.7,
177.8, 177.9, 178, 178.1, 178.2, 178.3, 178.4, 178.5, 178.6,
178.7, 178.8, 178.9, 179, 179.1, 179.2, 179.3, 179.4, 179.5,
179.6, 179.7, 179.8, 179.9, 180, 180.1, 180.2, 180.3, 180.4,
180.5, 180.6, 180.7, 180.8, 180.9, 181, 181.1, 181.2, 181.3,
181.4, 181.5, 181.6, 181.7, 181.8, 181.9, 182, 182.1, 182.2,
182.3, 182.4, 182.5, 182.6, 182.7, 182.8, 182.9, 183, 183.1,
183.2, 183.3, 183.4, 183.5, 183.6, 183.7, 183.8, 183.9, 184,
184.1, 184.2, 184.3, 184.4, 184.5, 184.6, 184.7, 184.8, 184.9,
185, 185.1, 185.2)
Also, I have a vector "slopezz":
> slopezz
[1] -2.1920 0.7034 0.6113 -1.2540 0.7513 2.3250 0.0791 -0.9713 1.1010 1.9490
[11] -1.4290 2.2500 0.8775
and another one-column data frame, "x":
> x
psi
psi1.Tim 171.4
psi2.Tim 171.8
psi3.Tim 175.1
psi4.Tim 175.7
psi5.Tim 176.3
psi6.Tim 177.8
psi7.Tim 178.7
psi8.Tim 180.1
psi9.Tim 181.5
psi10.Tim 182.4
psi11.Tim 183.8
psi12.Tim 184.8
Goal
There are 13 values in the "slopezz" and 12 in x$psi. In the data frame "veh", I want to add a new column "slope" that contains the values from "slopezz" but at the indices from x$psi.
Example:
The first value in "slopezz" is -2.1920 and in x$psi is 171.4. x$psi corresponds to veh$Tim. So, between 169.7 (first value in veh$Time) and 171.4, the "slope" variable contains the first value of -2.1920. Then, between 171.4 and 171.8 the second value of slope, 0.7034. And so on.
What I have tried
I can successfully create the new column by using ifelse and putting in the values of x$psi and "slopezz" manually.
## Example:
library(dplyr)
veh <- veh %>%
mutate(slope = ifelse(Tim<=171.4,slopezz[1],
ifelse(Tim>171.4 & Tim<=171.8, slopezz[2], ....
Code was long, so not putting the entire thing here.
But is there a better method where I don't have to manually put the Tim values taken from x$psi?
You had the right idea using dput() for veh$Tim; it would have helped had you used it for slopezz and x as well.
Here's a two line solution (where ix is a temporary index variable):
ix <- sapply(veh$Time, function(z) which.max(z <= c(x$psi, Inf)))
veh$slope <- slopezz[ix]
You were a bit ambiguous about what value of slopezz to use when, for example, veh$Tim equals 171.4. The code above uses intervals closed on the right.
You need joins, and something like tidyr::fill:
library(dplyr)
library(tidyr)
x %>% mutate(slopezz = slopezz[1:n()]) %>%
right_join(veh, by = c('psi' = 'Tim')) %>%
fill(slopezz, .direction = 'up')
# psi slopezz
# 1 169.7 -2.1920
# 2 169.8 -2.1920
# 3 169.9 -2.1920
# 4 170.0 -2.1920
# 5 170.1 -2.1920
# 6 170.2 -2.1920
# . ... ...
Note that this will leave the last four values as NA as you're filling up. If you want to then fill down, just add on %>% fill(slopezz).
Data
x <- structure(list(psi = c(171.4, 171.8, 175.1, 175.7, 176.3, 177.8,
178.7, 180.1, 181.5, 182.4, 183.8, 184.8)), .Names = "psi", class = "data.frame", row.names = c(NA, -12L))
slopezz <- c(-2.192, 0.7034, 0.6113, -1.254, 0.7513, 2.325, 0.0791, -0.9713,
1.101, 1.949, -1.429, 2.25, 0.8775)
veh <- structure(list(Tim = c(169.7, 169.8, 169.9, 170, 170.1, 170.2,
170.3, 170.4, 170.5, 170.6, 170.7, 170.8, 170.9, 171, 171.1,
171.2, 171.3, 171.4, 171.5, 171.6, 171.7, 171.8, 171.9, 172,
172.1, 172.2, 172.3, 172.4, 172.5, 172.6, 172.7, 172.8, 172.9,
173, 173.1, 173.2, 173.3, 173.4, 173.5, 173.6, 173.7, 173.8,
173.9, 174, 174.1, 174.2, 174.3, 174.4, 174.5, 174.6, 174.7,
174.8, 174.9, 175, 175.1, 175.2, 175.3, 175.4, 175.5, 175.6,
175.7, 175.8, 175.9, 176, 176.1, 176.2, 176.3, 176.4, 176.5,
176.6, 176.7, 176.8, 176.9, 177, 177.1, 177.2, 177.3, 177.4,
177.5, 177.6, 177.7, 177.8, 177.9, 178, 178.1, 178.2, 178.3,
178.4, 178.5, 178.6, 178.7, 178.8, 178.9, 179, 179.1, 179.2,
179.3, 179.4, 179.5, 179.6, 179.7, 179.8, 179.9, 180, 180.1,
180.2, 180.3, 180.4, 180.5, 180.6, 180.7, 180.8, 180.9, 181,
181.1, 181.2, 181.3, 181.4, 181.5, 181.6, 181.7, 181.8, 181.9,
182, 182.1, 182.2, 182.3, 182.4, 182.5, 182.6, 182.7, 182.8,
182.9, 183, 183.1, 183.2, 183.3, 183.4, 183.5, 183.6, 183.7,
183.8, 183.9, 184, 184.1, 184.2, 184.3, 184.4, 184.5, 184.6,
184.7, 184.8, 184.9, 185, 185.1, 185.2)), .Names = "Tim", row.names = c(NA,
-156L), class = "data.frame")
Here is a solution using the cut function from base R.
The data:
veh<-data.frame(Tim=c(169.7, 169.8, 169.9, 170, 170.1, 170.2, 170.3, 170.4, 170.5,
170.6, 170.7, 170.8, 170.9, 171, 171.1, 171.2, 171.3, 171.4,
171.5, 171.6, 171.7, 171.8, 171.9, 172, 172.1, 172.2, 172.3,
172.4, 172.5, 172.6, 172.7, 172.8, 172.9, 173, 173.1, 173.2,
173.3, 173.4, 173.5, 173.6, 173.7, 173.8, 173.9, 174, 174.1,
174.2, 174.3, 174.4, 174.5, 174.6, 174.7, 174.8, 174.9, 175,
175.1, 175.2, 175.3, 175.4, 175.5, 175.6, 175.7, 175.8, 175.9,
176, 176.1, 176.2, 176.3, 176.4, 176.5, 176.6, 176.7, 176.8,
176.9, 177, 177.1, 177.2, 177.3, 177.4, 177.5, 177.6, 177.7,
177.8, 177.9, 178, 178.1, 178.2, 178.3, 178.4, 178.5, 178.6,
178.7, 178.8, 178.9, 179, 179.1, 179.2, 179.3, 179.4, 179.5,
179.6, 179.7, 179.8, 179.9, 180, 180.1, 180.2, 180.3, 180.4,
180.5, 180.6, 180.7, 180.8, 180.9, 181, 181.1, 181.2, 181.3,
181.4, 181.5, 181.6, 181.7, 181.8, 181.9, 182, 182.1, 182.2,
182.3, 182.4, 182.5, 182.6, 182.7, 182.8, 182.9, 183, 183.1,
183.2, 183.3, 183.4, 183.5, 183.6, 183.7, 183.8, 183.9, 184,
184.1, 184.2, 184.3, 184.4, 184.5, 184.6, 184.7, 184.8, 184.9,
185, 185.1, 185.2))
slopezz<-c(-2.1920, 0.7034, 0.6113, -1.2540, 0.7513, 2.3250, 0.0791, -0.9713,
1.1010, 1.9490, -1.4290, 2.2500, 0.8775)
x<-c(171.4, 171.8, 175.1, 175.7, 176.3, 177.8, 178.7, 180.1, 181.5,
182.4, 183.8, 184.8)
Now define x to encompass the entire range of Tim:
x<-c(0,x,200)
veh$slope<-slopezz[cut(veh$Tim, breaks=x)]
The final dataframe for this example will be the column Tim and the new column slope.
A brute force way would be
veh$slope = rep(slopes[1], length(veh$Tim))
for (j in 1:12) veh$slope[ veh$Tim>x$psi[j] ] = slopes[j+1]

Reformat daily stock and return data to weekly/monthly

I have some stock data together with some returns that are presented below.
Now I would like to coerce both the daily price changes (open, high, low, close, volume, adj. close) and the returns given to weekly or monthly values.
I know that the weekly prices can be obtained by xts::to.weekly(), but this drops the return. I don't know the exact mechanism behind the to.weekly function, but the returns need to be summarized with the sum function (I'm thinking of using xts::apply.weekly()), but then this would not be consistent with the stock price data....
How can this transition to weekly or monthly timescale be achieved efficiently?
Data <-
structure(c(64.5, 67, 72, 76, 75.75, 72, 75.5, 76, 76, 78, 78,
77.5, 79.25, 80, 76.25, 84, 89.75, 90.75, 92.25, 95.75, 94.5,
95, 92, 95.75, 100, 98, 104.25, 101.25, 100.25, 96.5, 94.75,
89, 94, 91.25, 99.25, 100.25, 100.25, 98, 96.5, 94.75, 97.5,
96.25, 99.25, 97, 98, 98.75, 97.25, 98.75, 100.25, 100.25, 103.25,
105.75, 108.5, 108.25, 103.75, 101.5, 99.75, 100, 99, 94.5, 99,
101.5, 105, 64.75, 73.25, 76.5, 76.75, 76, 75.75, 76, 76, 76,
80.75, 79, 79.5, 83, 80.5, 76.75, 91.5, 92.75, 94.75, 100.25,
96, 97.5, 96.75, 92, 100, 101.75, 104, 105, 103.25, 100.75, 99,
95.5, 92.75, 94, 97.75, 103.75, 101, 100.25, 99.5, 97.75, 96.75,
98, 99, 100, 100.75, 99.25, 98.75, 98, 102.25, 101, 103, 105,
109, 110.5, 108.25, 105, 102.25, 100.75, 100, 99.75, 98.75, 102.5,
103, 107.25, 60.75, 66.75, 71.25, 74.25, 72.25, 71.5, 74.25,
76, 76, 77, 75.75, 76, 79, 75.75, 73.25, 82, 88.75, 89.5, 91.75,
92.25, 92.75, 92, 92, 94, 97.75, 96.5, 98.5, 99.25, 93.5, 94,
88.25, 87.5, 91, 91, 98.75, 98.5, 100.25, 95.75, 95.5, 90.75,
96.75, 96, 95.25, 97, 95.75, 95.75, 96.75, 98.5, 97.25, 100.25,
102.5, 105.5, 107.5, 103.5, 102.75, 97.5, 98.25, 100, 94, 94.25,
98, 100, 103.75, 64.25, 72.75, 75.75, 75, 73.75, 75.5, 76, 76,
76, 79, 76, 79.25, 81.25, 76.75, 75.75, 88, 90.25, 93.75, 97.5,
95, 95, 92, 92, 100, 97.75, 102.75, 99.75, 100.25, 97.25, 94.5,
89, 91.75, 92.5, 97, 99.5, 100.25, 100.25, 96.75, 96, 96, 97.5,
98, 95.5, 100.75, 98, 96.75, 98, 100.25, 99.5, 102.25, 103.5,
108, 109.25, 104, 102.75, 99, 100, 100, 94.5, 97.5, 102, 103,
104.5, 6808900, 8180500, 5628500, 3238900, 3765800, 3177100,
887600, 0, 0, 3923200, 2425700, 3331200, 4058600, 3682800, 3293500,
10525000, 5664200, 3982600, 4702300, 6479800, 2565300, 2480500,
0, 3653000, 3400, 4010500, 5145800, 2782200, 3925100, 2770700,
4618500, 2712300, 1675400, 3331500, 5343000, 1169700, 0, 2095400,
1016600, 3642600, 3729400, 3575300, 3396900, 1963400, 3547300,
1865100, 2496300, 3226800, 2333200, 4285900, 3933000, 7400700,
3325200, 1848400, 21000, 4273700, 1910400, 0, 3168000, 2356000,
2184800, 1950300, 2649900, 51.5865, 58.4112, 60.8199, 60.2178,
59.2141, 60.6192, 61.0207, 61.0207, 61.0207, 63.4294, 61.0207,
63.6301, 65.2359, 61.6228, 60.8199, 70.6555, 72.462, 75.2722,
78.2831, 76.2758, 76.2758, 73.8671, 73.8671, 80.2903, 78.4838,
82.4983, 80.0896, 80.4911, 78.0824, 75.8744, 71.4584, 73.6664,
74.2686, 77.8816, 79.8889, 80.4911, 80.4911, 77.6809, 77.0787,
77.0787, 78.2831, 78.6845, 76.6773, 80.8925, 78.6845, 77.6809,
78.6845, 80.4911, 79.8889, 82.0969, 83.1005, 86.7136, 87.7172,
83.5019, 82.4983, 79.4874, 80.2903, 80.2903, 75.8744, 78.2831,
81.8961, 82.699, 83.9034, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.086956169, -0.022499605, 0.051150683,
-0.029196965, 0.005013135, -0.029925048, -0.028277819, -0.058201449,
0.030899097, 0.00817469, 0.048647746, 0.025773739, 0.007537968,
0, -0.034913177, -0.007752227, 0, 0.015625588, 0.005127543, -0.025509471,
0.054973245, -0.027295485, -0.012754736, 0.012919521, 0.022960049,
-0.007481572, 0.027638383, 0.012224579, 0.043478679, 0.011573732,
-0.048055569, -0.012018888, -0.03649651, 0.010100972, 0, 0, 0,
0.046153001, 0.009803886, 0.014563659), .Dim = c(63L, 7L), .Dimnames = list(
NULL, c("Open", "High", "Low", "Close", "Volume", "Adj.Close",
"Return")), index = structure(c(1238544000, 1238630400, 1238716800,
1238976000, 1239062400, 1239148800, 1239235200, 1239321600, 1239580800,
1239667200, 1239753600, 1239840000, 1239926400, 1240185600, 1240272000,
1240358400, 1240444800, 1240531200, 1240790400, 1240876800, 1240963200,
1241049600, 1241136000, 1241395200, 1241481600, 1241568000, 1241654400,
1241740800, 1.242e+09, 1242086400, 1242172800, 1242259200, 1242345600,
1242604800, 1242691200, 1242777600, 1242864000, 1242950400, 1243209600,
1243296000, 1243382400, 1243468800, 1243555200, 1243814400, 1243900800,
1243987200, 1244073600, 1244160000, 1244419200, 1244505600, 1244592000,
1244678400, 1244764800, 1245024000, 1245110400, 1245196800, 1245283200,
1245369600, 1245628800, 1245715200, 1245801600, 1245888000, 1245974400),
tzone = "UTC", tclass = "Date"), class = c("xts", "zoo"), .indexCLASS = "Date",
tclass = "Date", .indexTZ = "UTC", tzone = "UTC")
Use period.apply (or apply.daily, apply.weekly, etc.) with your own custom function. Something like:
library(quantmod) # for Op, Hi, Lo, Cl, and Vo functions
myFun <- function(x) {
# need coredata, so c.xts will not be dispatched
cx <- coredata(x)
c(Open = first(Op(cx)),
Hi = max(Hi(cx)),
Low = min(Lo(cx)),
Close = last(cx[,"Close"]),
Volume = sum(Vo(cx)),
Adj.Close = last(cx[,"Adj.Close"]),
Return = sum(cx[,"Return"]))
}
out <- period.apply(Data, endpoints(Data, "months"), myFun)
# Open Hi Low Close Volume Adj.Close Return
# 2009-04-30 64.5 100.25 60.75 92.0 88802000 73.8671 0.0000000
# 2009-05-29 92.0 105.00 87.50 95.5 58597300 76.6773 0.0486306
# 2009-06-26 97.0 110.50 94.00 104.5 54739400 83.9034 0.1222869

ggvis barchart using dates as x axis

I have been switching over from ggplot to ggvis when working with shiny apps. I have figured out a lot but am really stumped when it comes to bar graphs. I have a timeseries with dates and values. I simply want bars instead of points for each value (I would ideally like to be able to plot multiple semi-transparent bars if anyone has had success there please share) but here I wanted to get one bar working.
Works with layer_points()
df %>% ggvis(~date, ~x) %>% layer_points() %>% scale_datetime("x")
Doesnt work with layer_bars()
df %>% ggvis(~date, ~x) %>% layer_bars() %>% scale_datetime("x")
Data I am using...
structure(list(date = structure(c(7680, 7687, 7694, 7701, 7708,
7715, 7722, 7729, 7736, 7743, 7750, 7757, 7764, 7771, 7778, 7785,
7792, 7799, 7806, 7813, 7820, 7827, 7834, 7841, 7848, 7855, 7862,
7869, 7876, 7883, 7890, 7897, 7904, 7911, 7918, 7925, 7932, 7939,
7946, 7953, 7960, 7967, 7974, 7981, 7988, 7995, 8002, 8009, 8016,
8023, 8030, 8037, 8044, 8051, 8058, 8065, 8072, 8079, 8086, 8093,
8100, 8107, 8114, 8121, 8128, 8135, 8142, 8149, 8156, 8163, 8170,
8177, 8184, 8191, 8198, 8205, 8212, 8219, 8226, 8233, 8240, 8247,
8254, 8261, 8268, 8275, 8282, 8289, 8296, 8303, 8310, 8317, 8324,
8331, 8338, 8345, 8352, 8359, 8366, 8373, 8380, 8387, 8394, 8401,
8408, 8415, 8422, 8429, 8436, 8443, 8450, 8457, 8464, 8471, 8478,
8485, 8492, 8499, 8506, 8513, 8520, 8527, 8534, 8541, 8548, 8555,
8562, 8569, 8576, 8583, 8590, 8597, 8604, 8611, 8618, 8625, 8632,
8639, 8646, 8653, 8660, 8667, 8674, 8681, 8688, 8695, 8702, 8709,
8716, 8723, 8730, 8737, 8744, 8751, 8758, 8765, 8772, 8779, 8786,
8793, 8800, 8807, 8814, 8821, 8828, 8835, 8842, 8849, 8856, 8863,
8870, 8877, 8884, 8891, 8898, 8905, 8912, 8919, 8926, 8933, 8940,
8947, 8954, 8961, 8968, 8975, 8982, 8989, 8996, 9003, 9010, 9017,
9024, 9031, 9038, 9045, 9052, 9059, 9066, 9073), class = "Date"),
x = c(-0.034038302, 0.122310949, -0.002797319, 0.026515253,
0.039961798, 0.034473263, 0.00549937, -0.024125944, 0.000132490000000001,
0.011038357, -0.02135072, 0.030663311, -0.008915551, 0.004855042,
0.01563688, -0.007397493, 0.013569146, -0.004968811, -0.00250391,
0.014624532, 0.036937453, -0.023685917, 0.018921356, -0.003066779,
-0.009217771, 0.005317513, 0.010378968, 0.001580798, -0.015085972,
-0.000121644000000001, 0.020468644, 0.007925229, 0.007721276,
-0.003123545, -0.018317891, -0.014900591, 0.003260844, -0.001565358,
-0.014833886, 0.00366766, 0.014297139, -0.00725552, 0.012207931,
0.024035152, -0.024195095, -0.0043564, 0.000847468, 0.033031596,
0.023685033, 0.025143071, 0.046264348, 0.038285177, -0.009180356,
-0.01630399, -0.010131294, -0.009939386, -0.007620427, 0.013062259,
0.009912238, 0.000192973, -0.01683559, -0.002627549, 0.019836063,
-0.019946159, -0.020124331, 0.012921737, 0.034604405, -0.020774015,
0.00334805, 0.002271156, -0.018676732, 0.019160923, -0.01945997,
-0.014342636, -0.004867796, -0.010002446, -0.004372991, 0.023164369,
0.019824112, -0.00321832, -0.015785746, 0.040836652, 0.00148831,
0.012084485, -0.009603897, -0.004642148, -0.008399234, 0.010463218,
0.000256571000000001, -0.01978405, -0.003439498, -0.015669975,
0.026180724, 0.020373255, 0.019160773, 0.00692683, 0.010215506,
0.010861939, 0.012041143, 0.025734568, -0.004828156, 0.006914552,
-0.00720089, -0.000538489999999999, -0.008479448, 0.022926604,
0.002131842, -0.003688597, 0.025325639, -0.009562293, -0.024336741,
0.012907537, 0.004339383, 0.010744364, -0.013058765, -0.003672014,
-0.023887493, 0.01062259, 0.02088054, -0.035249878, -0.001462821,
0.01904368, -0.001308787, 0.009203217, 0.019856479, 0.011296979,
0.010039545, -0.01559142, 0.006083419, -0.017958978, -0.007488063,
0.01236649, -0.004459064, -0.004375386, 0.025500722, 0.005557851,
0.008444321, 0.002827649, 0.020320308, 0.031611803, -0.010199803,
-0.009425874, 0.007942729, -2.59379999999999e-05, 0.016669077,
-0.011666062, 0.022835386, -0.025599107, 0.013562535, -0.018365192,
0.018148786, 0.016649144, -0.009530455, 0.012996597, 0.002034778,
-0.005926478, -0.004897238, -0.004419719, 0.010848926, -0.006039757,
-0.030287605, 0.019221837, 0.001808161, -0.009566133, 0.005009292,
0.005365023, -0.004879922, -0.024637933, -0.0186584, 0.004786059,
-0.008245254, -0.000106243, -0.001714888, -0.017804006, -0.021200061,
0.003812757, 0.021940886, 0.002270448, -0.015417493, -0.045754612,
-0.003468442, -0.006242659, 0.022383824, -0.018753927, 0.008577571,
0.008655048, 0.02374636, 0.029522811, 0.009946946, 0.015419714,
-0.016714623, -0.014616188, 0.019670855, -0.038979063, 0.020491563,
-0.009640674, 0.046051144, -0.021434575, 0.000190443999999998,
-0.029013969), id = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148,
149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172,
173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196,
197, 198, 199, 200)), .Names = c("date", "x", "id"), row.names = 53:252, class = "data.frame")
Set format df$date as character:
df$date <- as.character(df$date)
and then:
df %>% ggvis(~date, ~x) %>% layer_bars()

Selecting just some rows of a RGList

I am using the package Limma to analyse some data. After reading the raw data with read.maimagenes I get a RGList object. R.cut and G.cut are a value of class numeric and I want the values above them. I tried something like this:
RG$R <- RG$R[RG$R>R.cut]
RG$G <- RG$G[RG$G>G.cut]
But this converts the class of RG$R from matrix to numeric how could I keep the matrix class (I don't know if introducing some NA values would affect the rest of the analyse). I have tried subset like this:
RG.probe$R <- subset(x=RG, subset=RG$R>R.cut)
But it keeps returning an error Error: Two subscripts required
How can this be done?
Aside: If I would like to just get the rows that are above the R.cut and G.cut?
Possible solution:
I have found that with ifelse I can do it although I must introduce a value for the ones that are under the cut, and I haven't found the way to check if both R and G channels are above each cut.
RG$R<-ifelse(RG$R>R.cut, RG$R, '')
RG$G<-ifelse(RG$G>G.cut, RG$G, '')
Although it is converted to character, and therefore I cannot do further analysis.
Data to make it reproducible:
library(limma)
RG<-read.maimages(path, source='agilent')
class(RG)
[1] "RGList"
attr(,"package")
[1] "limma"
dput(head(RG$R))
structure(c(2893, 81.5, 80.5, 140208, 4512, 6272, 4934, 195,
184.5, 164092, 11819, 10569, 1689.5, 83, 82, 68996, 2260.5, 3603,
2470, 84, 77, 96750, 3203, 5223, 3246, 85.5, 104.5, 54773, 519.5,
8244.5, 1807, 86.5, 88, 204574, 15693, 8939.5, 2040, 87, 95,
131880, 7346, 9922.5, 1445, 76, 85.5, 125598, 3863, 5758.5, 2626,
87.5, 85, 180266, 18173, 20171.5, 1811.5, 84, 87.5, 122498, 3993,
5857, 1799, 87.5, 82, 123220, 3780, 5964, 1706, 77.5, 80, 124463,
3390, 5070, 3787, 81.5, 88, 65874, 269, 781.5, 1476, 90, 89,
122445, 4232, 6479, 2788, 82, 87.5, 80669, 791, 7440.5, 1503,
81, 88, 124702, 4270, 6111, 2012.5, 93.5, 90, 215820, 4555, 3101,
1727.5, 102, 109, 131316, 4284, 6638, 2009, 95.5, 111.5, 175474,
12665, 17213, 1532, 87.5, 84.5, 117568, 4098, 6100, 1436, 83,
91, 118472, 4067.5, 6114, 1651.5, 83, 82, 127308, 4150, 6277,
2028.5, 85.5, 89, 74816, 896.5, 7697, 2698, 84, 92.5, 99431,
1273, 9182.5, 1833.5, 100, 104, 163604, 15582, 12146, 2359, 102,
109, 159301, 17229, 9822.5, 1857, 86, 88, 130319, 4354.5, 6266.5,
1887, 87, 87, 133386, 11639.5, 8931, 2304.5, 86.5, 87, 91022,
1011, 14524, 1353, 84, 88, 114282, 3935, 5944, 1487, 83, 87,
125507, 4138, 5804, 3379, 86.5, 88, 63703.5, 331, 1167, 1778,
87, 83.5, 123988, 4366, 6670, 1862, 94.5, 92, 134174, 4558, 6881,
2388.5, 82, 91.5, 174744, 8570, 10677, 4374, 94, 94, 179579,
12753, 10869, 3747.5, 115, 144.5, 133809, 3710, 5406, 5062, 93.5,
92, 207843, 13220, 6774, 3294, 78, 82.5, 149764, 3774, 5582,
5303, 93, 100, 93479.5, 803, 6709, 2969, 86.5, 101, 149011, 4043,
5407, 5488, 106, 118.5, 191053, 9990.5, 12194, 4308, 89, 85,
143087, 3926.5, 5370.5, 5168, 87, 91.5, 137415, 4028, 5671, 4649.5,
91, 90, 147328, 4102, 5614.5, 7225, 87, 85, 179052, 15612, 16908,
5815.5, 84, 88, 200883, 13229, 11482, 3551, 101, 125, 224012,
20461, 16149.5, 3992, 98, 83, 134744, 3569, 5068, 4817, 97, 92,
142087, 4203, 5678, 5436, 108, 84.5, 195104, 11299, 13246), .Dim = c(6L,
51L), .Dimnames = list(NULL, c("US23502326_253482110017_S01_GE2_1105_Oct12_1_1",
"US23502326_253482110017_S01_GE2_1105_Oct12_2_1", "US23502326_253482110017_S01_GE2_1105_Oct12_2_2",
"US23502326_253482110017_S01_GE2_1105_Oct12_2_3", "US23502326_253482110017_S01_GE2_1105_Oct12_2_4",
"US23502326_253482110027_S01_GE2_1105_Oct12_1_1", "US23502326_253482110027_S01_GE2_1105_Oct12_1_2",
"US23502326_253482110027_S01_GE2_1105_Oct12_1_3", "US23502326_253482110027_S01_GE2_1105_Oct12_1_4",
"US23502326_253482110027_S01_GE2_1105_Oct12_2_1", "US23502326_253482110027_S01_GE2_1105_Oct12_2_2",
"US23502326_253482110027_S01_GE2_1105_Oct12_2_3", "US23502326_253482110027_S01_GE2_1105_Oct12_2_4",
"US23502326_253482110028_S01_GE2_1105_Oct12_1_1", "US23502326_253482110028_S01_GE2_1105_Oct12_1_2",
"US23502326_253482110028_S01_GE2_1105_Oct12_1_4", "US23502326_253482110028_S01_GE2_1105_Oct12_2_1",
"US23502326_253482110028_S01_GE2_1105_Oct12_2_2", "US23502326_253482110028_S01_GE2_1105_Oct12_2_3",
"US23502326_253482110029_S01_GE2_1105_Oct12_1_1", "US23502326_253482110029_S01_GE2_1105_Oct12_1_2",
"US23502326_253482110029_S01_GE2_1105_Oct12_1_3", "US23502326_253482110029_S01_GE2_1105_Oct12_1_4",
"US23502326_253482110029_S01_GE2_1105_Oct12_2_1", "US23502326_253482110029_S01_GE2_1105_Oct12_2_2",
"US23502326_253482110029_S01_GE2_1105_Oct12_2_3", "US23502326_253482110029_S01_GE2_1105_Oct12_2_4",
"US23502326_253482110030_S01_GE2_1105_Oct12_1_1", "US23502326_253482110030_S01_GE2_1105_Oct12_1_2",
"US23502326_253482110030_S01_GE2_1105_Oct12_1_3", "US23502326_253482110030_S01_GE2_1105_Oct12_1_4",
"US23502326_253482110030_S01_GE2_1105_Oct12_2_1", "US23502326_253482110030_S01_GE2_1105_Oct12_2_2",
"US23502326_253482110030_S01_GE2_1105_Oct12_2_3", "US23502326_253482110030_S01_GE2_1105_Oct12_2_4",
"US23502326_253482110031_S01_GE2_1105_Oct12_1_1", "US23502326_253482110031_S01_GE2_1105_Oct12_1_2",
"US23502326_253482110031_S01_GE2_1105_Oct12_1_3", "US23502326_253482110031_S01_GE2_1105_Oct12_1_4",
"US23502326_253482110031_S01_GE2_1105_Oct12_2_1", "US23502326_253482110031_S01_GE2_1105_Oct12_2_2",
"US23502326_253482110031_S01_GE2_1105_Oct12_2_3", "US23502326_253482110031_S01_GE2_1105_Oct12_2_4",
"US23502326_253482110049_S01_GE2_1105_Oct12_1_1", "US23502326_253482110049_S01_GE2_1105_Oct12_1_2",
"US23502326_253482110049_S01_GE2_1105_Oct12_1_3", "US23502326_253482110049_S01_GE2_1105_Oct12_1_4",
"US23502326_253482110049_S01_GE2_1105_Oct12_2_1", "US23502326_253482110049_S01_GE2_1105_Oct12_2_2",
"US23502326_253482110049_S01_GE2_1105_Oct12_2_3", "US23502326_253482110049_S01_GE2_1105_Oct12_2_4"
)))
dput(head(RG$G))
structure(c(2324, 58, 52, 98015, 9800, 5284, 1472, 114, 92.5,
27879, 2296, 3272.5, 3637, 216, 204.5, 34898, 731, 5084, 3466,
77, 74, 32543, 497, 7416, 1344, 79.5, 99, 52753, 2363, 3457,
686, 39, 44.5, 32866, 2937, 4324, 910, 42, 40, 42361, 2780, 4072,
1587, 83.5, 97, 79659, 7667, 10103, 754, 49.5, 44, 23664, 2962,
4166, 1390.5, 136, 156.5, 70132.5, 7914, 4876, 1609, 99, 125,
25923.5, 610, 5125, 1526, 198.5, 157, 94640.5, 10408, 9233, 1060,
42, 37, 70033, 3144, 4355.5, 1465, 89, 91, 99188, 9587, 7547,
743, 61.5, 60, 65888, 3247, 4676.5, 1931.5, 89, 84, 65967, 11226,
7757, 873.5, 56, 66, 20126.5, 3291, 4736, 1339.5, 298, 300, 75324,
6712, 8500, 894, 65, 86, 26341.5, 3132.5, 4647, 2372, 80, 81.5,
73418.5, 5026, 7612, 1564, 70, 73, 77180, 7802.5, 9454, 1315,
90, 85, 20562, 340, 5337, 868.5, 49, 55, 64712.5, 2947, 4260,
798, 46, 48, 52505, 3380, 4663.5, 904, 69.5, 80, 33371.5, 3300,
4997, 813, 73, 81, 29552, 2932, 4632.5, 1696.5, 187, 324, 63647,
6407, 8571.5, 872, 39.5, 52, 24518, 3094, 4387, 752.5, 54, 52,
48299.5, 3221, 4278, 2631, 61, 72, 27229, 513, 5019, 1256.5,
61, 63, 74560, 11016, 9019, 942, 57, 55, 70933.5, 3526.5, 5383,
1457.5, 162, 193.5, 86276, 8154, 12084, 1590, 213, 293, 66871,
6580, 9535, 833.5, 57, 62.5, 36416, 3229, 4600, 2161.5, 53.5,
42.5, 39157.5, 2952, 3977, 3481, 67, 68, 18675, 152, 536, 1977,
57, 55.5, 32861, 2785, 3812, 4739.5, 112.5, 113.5, 104923, 6231,
8198, 1907, 57.5, 69, 76674.5, 3219, 4244, 3879.5, 183.5, 171,
110822, 9582, 8426, 1746, 74.5, 74, 33327, 2774, 4017, 3333,
187, 270.5, 83696, 6616, 7080, 4737, 38, 37, 30041, 429.5, 3970,
3347, 45, 46, 106822, 8003.5, 7137.5, 2431, 32, 35, 32985, 3121,
4179, 2535.5, 28, 34, 36131.5, 3135, 4126, 1929, 42, 65, 47428,
3300, 4626.5, 5371, 54.5, 43.5, 108175, 9983, 6182, 5139.5, 34,
28, 26774, 152, 518, 2621, 48, 32, 44499, 3409, 4643), .Dim = c(6L,
51L), .Dimnames = list(NULL, c("US23502326_253482110017_S01_GE2_1105_Oct12_1_1",
"US23502326_253482110017_S01_GE2_1105_Oct12_2_1", "US23502326_253482110017_S01_GE2_1105_Oct12_2_2",
"US23502326_253482110017_S01_GE2_1105_Oct12_2_3", "US23502326_253482110017_S01_GE2_1105_Oct12_2_4",
"US23502326_253482110027_S01_GE2_1105_Oct12_1_1", "US23502326_253482110027_S01_GE2_1105_Oct12_1_2",
"US23502326_253482110027_S01_GE2_1105_Oct12_1_3", "US23502326_253482110027_S01_GE2_1105_Oct12_1_4",
"US23502326_253482110027_S01_GE2_1105_Oct12_2_1", "US23502326_253482110027_S01_GE2_1105_Oct12_2_2",
"US23502326_253482110027_S01_GE2_1105_Oct12_2_3", "US23502326_253482110027_S01_GE2_1105_Oct12_2_4",
"US23502326_253482110028_S01_GE2_1105_Oct12_1_1", "US23502326_253482110028_S01_GE2_1105_Oct12_1_2",
"US23502326_253482110028_S01_GE2_1105_Oct12_1_4", "US23502326_253482110028_S01_GE2_1105_Oct12_2_1",
"US23502326_253482110028_S01_GE2_1105_Oct12_2_2", "US23502326_253482110028_S01_GE2_1105_Oct12_2_3",
"US23502326_253482110029_S01_GE2_1105_Oct12_1_1", "US23502326_253482110029_S01_GE2_1105_Oct12_1_2",
"US23502326_253482110029_S01_GE2_1105_Oct12_1_3", "US23502326_253482110029_S01_GE2_1105_Oct12_1_4",
"US23502326_253482110029_S01_GE2_1105_Oct12_2_1", "US23502326_253482110029_S01_GE2_1105_Oct12_2_2",
"US23502326_253482110029_S01_GE2_1105_Oct12_2_3", "US23502326_253482110029_S01_GE2_1105_Oct12_2_4",
"US23502326_253482110030_S01_GE2_1105_Oct12_1_1", "US23502326_253482110030_S01_GE2_1105_Oct12_1_2",
"US23502326_253482110030_S01_GE2_1105_Oct12_1_3", "US23502326_253482110030_S01_GE2_1105_Oct12_1_4",
"US23502326_253482110030_S01_GE2_1105_Oct12_2_1", "US23502326_253482110030_S01_GE2_1105_Oct12_2_2",
"US23502326_253482110030_S01_GE2_1105_Oct12_2_3", "US23502326_253482110030_S01_GE2_1105_Oct12_2_4",
"US23502326_253482110031_S01_GE2_1105_Oct12_1_1", "US23502326_253482110031_S01_GE2_1105_Oct12_1_2",
"US23502326_253482110031_S01_GE2_1105_Oct12_1_3", "US23502326_253482110031_S01_GE2_1105_Oct12_1_4",
"US23502326_253482110031_S01_GE2_1105_Oct12_2_1", "US23502326_253482110031_S01_GE2_1105_Oct12_2_2",
"US23502326_253482110031_S01_GE2_1105_Oct12_2_3", "US23502326_253482110031_S01_GE2_1105_Oct12_2_4",
"US23502326_253482110049_S01_GE2_1105_Oct12_1_1", "US23502326_253482110049_S01_GE2_1105_Oct12_1_2",
"US23502326_253482110049_S01_GE2_1105_Oct12_1_3", "US23502326_253482110049_S01_GE2_1105_Oct12_1_4",
"US23502326_253482110049_S01_GE2_1105_Oct12_2_1", "US23502326_253482110049_S01_GE2_1105_Oct12_2_2",
"US23502326_253482110049_S01_GE2_1105_Oct12_2_3", "US23502326_253482110049_S01_GE2_1105_Oct12_2_4"
)))
From the dput you can create an RGList by new("RGList") I know it is to much data but as I previously asked I don't know how to short the output.
The solution that finally I got is doing almost the same:
RG$G <- ifelse(RG$R>R.cut, RG$G, NA)
RG$R <- ifelse(RG$G>G.cut, RG$R, NA)
Deleting this values seems to increase the Fold Change of each gene as already happened comparing the original RG with the RG with deleted values as in the question.

Resources