Reading list like values from dataframe cell - r

I have pulled data from facebook api fbRads. Here is the sample of data frame I have:
mydata <- fread('ID,ACTIONS
02,"list(action_type = c("link_click", "post_reaction", "page_engagement", "post_engagement"), value = c("1", "4", "5", "5"))"
03,"list(action_type = c("app_custom_event.fb_mobile_activate_app", "app_custom_event.fb_mobile_add_to_cart", "app_custom_event.fb_mobile_content_view", "app_custom_event.fb_mobile_purchase", "app_custom_event.fb_mobile_search", "app_custom_event.other", "like", "link_click", "mobile_app_install", "offsite_conversion.fb_pixel_add_to_cart", "offsite_conversion.fb_pixel_add_to_wishlist", "offsite_conversion.fb_pixel_lead", "offsite_conversion.fb_pixel_purchase", "offsite_conversion.fb_pixel_search", "offsite_conversion.fb_pixel_view_content", "post_reaction", "page_engagement", "post_engagement", "offsite_conversion", "app_custom_event"), value = c("994", "219", "1696", "9", "47", "425", "67", "2267", "37", "348", "53", "3", "7", "218", "3286", "145", "2479", "2412", "3915", "3390"))"
04,"NULL"
05,"list(action_type = c("app_custom_event.fb_mobile_activate_app", "app_custom_event.fb_mobile_add_to_cart", "app_custom_event.fb_mobile_content_view", "app_custom_event.fb_mobile_purchase", "app_custom_event.fb_mobile_search", "app_custom_event.other", "like", "link_click", "mobile_app_install", "offsite_conversion.fb_pixel_add_to_cart", "offsite_conversion.fb_pixel_add_to_wishlist", "offsite_conversion.fb_pixel_lead", "offsite_conversion.fb_pixel_purchase", "offsite_conversion.fb_pixel_search", "offsite_conversion.fb_pixel_view_content", "post", "post_reaction", "page_engagement", "post_engagement", "offsite_conversion", "app_custom_event"), value = c("1703", "188", "2233", "13", "155", "731", "229", "2568", "62", "303", "46", "7", "17", "257", "4433", "1", "473", "3271", "3042", "5063", "5023"))"')
I need find values for app_custom_event.fb_mobile_purchase against each id. ACTION column contains two list in each cell i.e. action_type and value.
The output which I am expecting is :
mydata <- fread('ID,app_custom_event.fb_mobile_purchase
02,"NULL"
03,"9"
04,"NULL"
05,"13"')
Do I need to use dictionaries to get the values? Any approach will be highly appreciated.

Here is a start:
lapply(mydata$ACTIONS, function(i){
x <- eval(parse(text = i))
ix <- which(x$action_type == "app_custom_event.fb_mobile_purchase")
x$value[ ix ]
})
I don't know about fbRads package, but it must have some "read" function, to avoid this problem.

Related

Group periodic data in dataframe

I have a dataset comprised of periodic data. I want to group the data by period.
The full dataset is provided: LINK
Data for one period of the dataset is provided and ploted:
> dput(DATA[1:122,c(2,9)])
structure(list(Actuator.Force = c(-4853.5854, -4566.9771, -4198.7612,
-3774.5527, -3317.6958, -2847.5229, -2364.7585, -1880.9485, -1405.4272,
-930.289, -467.04822, -18.867363, 421.17499, 838.86719, 1239.9121,
1626.0669, 1990.6389, 2334.0852, 2655.344, 2962.0227, 3243.7817,
3506.2249, 3744.2622, 3959.8271, 4156.7061, 4324.9048, 4469.229,
4591.6689, 4687.4194, 4764.0801, 4814.6167, 4840.313, 4846.0181,
4826.3135, 4777.6553, 4696.0791, 4583.854, 4442.457, 4272.5254,
4076.7224, 3851.1211, 3603.1853, 3330.7456, 3038.3157, 2724.115,
2386.5476, 2032.5809, 1660.0547, 1268.0084, 859.16675, 432.4075,
-14.131592, -479.29309, -955.67108, -1444.614, -1937.2562, -2437.0085,
-2941.8914, -3450.9009, -3959.9597, -4468.9795, -4981.2549, -5492.6997,
-6002.334, -6510.5425, -7016.2432, -7517.8286, -8013.1348, -8500.4199,
-8974.8867, -9439.5479, -9890.5938, -10326.367, -10744.421, -11147.754,
-11534.83, -11902.651, -12248.997, -12577.919, -12885.458, -13172.309,
-13441.554, -13691.502, -13922.634, -14127.116, -14305.272, -14458.267,
-14582.934, -14685.274, -14758.539, -14806.058, -14830.719, -14836.625,
-14822.204, -14773.916, -14700.484, -14597.968, -14469.834, -14312.099,
-14126.422, -13915.136, -13676.505, -13412.388, -13120.703, -12807.961,
-12473.883, -12115.751, -11740.082, -11342.633, -10929.945, -10502.158,
-10062.869, -9611.8271, -9146.6006, -8673.3545, -8191.7417, -7700.769,
-7200.9346, -6695.8809, -6185.2378, -5670.8711, -5154.9995),
Rotation = c(-0.005985651, -0.00565783616666667, -0.00522075016666667,
-0.0046743925, -0.00406732866666667, -0.00343598223333333,
-0.00286534205, -0.00219757165, -0.00156622503333333, -0.000934878566666667,
-0.000267108158333333, 0.000303531998333333, 0.00084988955,
0.0013962471, 0.00193046351666667, 0.00242825596666667, 0.00288962463333333,
0.0033995583, 0.0038366445, 0.00424944783333333, 0.004637969,
0.0050507725, 0.005378587, 0.00565783616666667, 0.00594922716666667,
0.00620419383333333, 0.006410596, 0.0065684325, 0.00670198666666667,
0.00683554116666667, 0.0069205295, 0.00699337683333333, 0.0070055185,
0.006993377, 0.00696909483333333, 0.00688410516666667, 0.006774834,
0.00659271483333333, 0.006386313, 0.00613134633333333, 0.0058399555,
0.0055364235, 0.00518432633333333, 0.00483222916666667, 0.0044072845,
0.00403090483333333, 0.00353311216666667, 0.0029988961, 0.00251324506666667,
0.0020275938, 0.00144481233333333, 0.00086203085, 0.000303531998333333,
-0.000315673273333333, -0.000983443666666667, -0.00162693151666667,
-0.00233112578333333, -0.0029988961, -0.00366666666666667,
-0.00433443683333333, -0.00496578316666667, -0.00563355366666667,
-0.0062770415, -0.0069690945, -0.0076611475, -0.00836534183333333,
-0.00902097083333333, -0.00968874116666667, -0.0103443703333333,
-0.0109514346666667, -0.011594922, -0.012177704, -0.0127969093333333,
-0.0133918318333333, -0.0139746131666667, -0.0145209698333333,
-0.014982339, -0.0154437081666667, -0.0159050765, -0.0163178798333333,
-0.0167185421666667, -0.0170706398333333, -0.0174105943333333,
-0.0177505506666667, -0.018017659, -0.0182483433333333, -0.0184547455,
-0.0186490056666667, -0.0187704183333333, -0.01887969, -0.0189525386666667,
-0.018988962, -0.0190011033333333, -0.018988962, -0.0189768206666667,
-0.0189282553333333, -0.0188189838333333, -0.018673289, -0.018442604,
-0.0182240605, -0.017993377, -0.0176534206666667, -0.0173256068333333,
-0.0169492263333333, -0.0165485635, -0.0161357608333333,
-0.0156622516666667, -0.0152373058333333, -0.0147152313333333,
-0.0141931568333333, -0.0136103748333333, -0.0130275935,
-0.0123962468333333, -0.0118013235, -0.0112064015, -0.0105507718333333,
-0.00993156683333333, -0.0092637965, -0.008620309, -0.00791611466666667,
-0.00719977883333333, -0.0065441495)), row.names = 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"), class = "data.frame")
The next row of the data starts a new period and so on. I want to group the rows by the periods that exist in the data.
Although the code provided in this example can find the periods if fully completed data is provided (it worked for the first three periods), when applied to the entire dataset of periodic data, it resulted in NaNs.
ssp <- spectrum(DATA$Rotation, plot = FALSE, method = "ar", n.freq = 1e6)
period <- 1 / with(ssp, freq[spec == max(spec)])
DATA$Loop <- (seq_len(nrow(DATA)) %/% period) + 1
Here's an approach where I define a region where both the Rotation is increasing and Rotation is at least as high as the starting value. Then I count how many times we enter that region and that's the period number.
library(dplyr)
Rot_start = DATA$Rotation[1]
rbind(DATA, DATA) %>% # to demonstrate two cycles
mutate(Rot_pos = Rotation > lag(Rotation, default = -1),
Rot_rightside = Rotation >= Rot_start,
Rot_region = Rot_pos & Rot_rightside,
new_period = Rot_region & !(lag(Rot_region, default = FALSE)),
period = cumsum(new_period))
# more succinct, same workings
# mutate(Rot_region = Rotation > lag(Rotation, default = -1) & Rotation >= Rot_start,
# period = cumsum(Rot_region & !(lag(Rot_region, default = FALSE))))

scale_x_continuous : Discrete value supplied to continuous scale

I'm a beginner in R. I get this error
Error: Discrete value supplied to continuous scale
when I try to use
scale_x_continuous(breaks=1:10)
The plot I get is the following one. As you can see, the axis needs to be reduced...
I get my data from a csv file
dput(head(Data, 20))
structure(list(Pmanche = structure(1:20, .Label = c("0", "0,1",
"0,2", "0,3", "0,4", "0,5", "0,6", "0,7", "0,8", "0,9", "1",
"1,1", "1,2", "1,3", "1,4", "1,5", "1,6", "1,7", "1,8", "1,9",
"10", "10,1", "10,2", "10,3", "10,4", "10,5", "10,6", "10,7",
"10,8", "10,9", "100", "11", "11,1", "11,2", "11,3", "11,4",
"11,5", "11,6", "11,7", "11,8", "11,9", "12", "12,1", "12,2",
"12,3", "12,4", "12,5", "12,6", "12,7", "12,8", "12,9", "13",
"13,1", "13,2", "13,3", "13,4", "13,5", "13,6", "13,7", "13,8",
"13,9", "14", "14,1", "14,2", "14,3", "14,4", "14,5", "14,6",
"14,7", "14,8", "14,9", "15", "15,1", "15,2", "15,3", "15,4",
"15,5", "15,6", "15,7", "15,8", "15,9", "16", "16,1", "16,2",
"16,3", "16,4", "16,5", "16,6", "16,7", "16,8", "16,9", "17",
"17,1", "17,2", "17,3", "17,4", "17,5", "17,6", "17,7", "17,8",
"17,9", "18", "18,1", "18,2", "18,3", "18,4", "18,5", "18,6",
"18,7", "18,8", "18,9", "19", "19,1", "19,2", "19,3", "19,4",
"19,5", "19,6", "19,7", "19,8", "19,9", "2", "2,1", "2,2", "2,3",
"2,4", "2,5", "2,6", "2,7", "2,8", "2,9", "20", "20,1", "20,2",
"20,3", "20,4", "20,5", "20,6", "20,7", "20,8", "20,9", "21",
"21,1", "21,2", "21,3", "21,4", "21,5", "21,6", "21,7", "21,8",
"21,9", "22", "22,1", "22,2", "22,3", "22,4", "22,5", "22,6",
"22,7", "22,8", "22,9", "23", "23,1", "23,2", "23,3", "23,4",
"23,5", "23,6", "23,7", "23,8", "23,9", "24", "24,1", "24,2",
"24,3", "24,4", "24,5", "24,6", "24,7", "24,8", "24,9", "25",
"25,1", "25,2", "25,3", "25,4", "25,5", "25,6", "25,7", "25,8",
"25,9", "26", "26,1", "26,2", "26,3", "26,4", "26,5", "26,6",
"26,7", "26,8", "26,9", "27", "27,1", "27,2", "27,3", "27,4",
"27,5", "27,6", "27,7", "27,8", "27,9", "28", "28,1", "28,2",
"28,3", "28,4", "28,5", "28,6", "28,7", "28,8", "28,9", "29",
"29,1", "29,2", "29,3", "29,4", "29,5", "29,6", "29,7", "29,8",
"29,9", "3", "3,1", "3,2", "3,3", "3,4", "3,5", "3,6", "3,7",
"3,8", "3,9", "30", "30,1", "30,2", "30,3", "30,4", "30,5", "30,6",
"30,7", "30,8", "30,9", "31", "31,1", "31,2", "31,3", "31,4",
"31,5", "31,6", "31,7", "31,8", "31,9", "32", "32,1", "32,2",
"32,3", "32,4", "32,5", "32,6", "32,7", "32,8", "32,9", "33",
"33,1", "33,2", "33,3", "33,4", "33,5", "33,6", "33,7", "33,8",
"33,9", "34", "34,1", "34,2", "34,3", "34,4", "34,5", "34,6",
"34,7", "34,8", "34,9", "35", "35,1", "35,2", "35,3", "35,4",
"35,5", "35,6", "35,7", "35,8", "35,9", "36", "36,1", "36,2",
"36,3", "36,4", "36,5", "36,6", "36,7", "36,8", "36,9", "37",
"37,1", "37,2", "37,3", "37,4", "37,5", "37,6", "37,7", "37,8",
"37,9", "38", "38,1", "38,2", "38,3", "38,4", "38,5", "38,6",
"38,7", "38,8", "38,9", "39", "39,1", "39,2", "39,3", "39,4",
"39,5", "39,6", "39,7", "39,8", "39,9", "4", "4,1", "4,2", "4,3",
"4,4", "4,5", "4,6", "4,7", "4,8", "4,9", "40", "40,1", "40,2",
"40,3", "40,4", "40,5", "40,6", "40,7", "40,8", "40,9", "41",
"41,1", "41,2", "41,3", "41,4", "41,5", "41,6", "41,7", "41,8",
"41,9", "42", "42,1", "42,2", "42,3", "42,4", "42,5", "42,6",
"42,7", "42,8", "42,9", "43", "43,1", "43,2", "43,3", "43,4",
"43,5", "43,6", "43,7", "43,8", "43,9", "44", "44,1", "44,2",
"44,3", "44,4", "44,5", "44,6", "44,7", "44,8", "44,9", "45",
"45,1", "45,2", "45,3", "45,4", "45,5", "45,6", "45,7", "45,8",
"45,9", "46", "46,1", "46,2", "46,3", "46,4", "46,5", "46,6",
"46,7", "46,8", "46,9", "47", "47,1", "47,2", "47,3", "47,4",
"47,5", "47,6", "47,7", "47,8", "47,9", "48", "48,1", "48,2",
"48,3", "48,4", "48,5", "48,6", "48,7", "48,8", "48,9", "49",
"49,1", "49,2", "49,3", "49,4", "49,5", "49,6", "49,7", "49,8",
"49,9", "5", "5,1", "5,2", "5,3", "5,4", "5,5", "5,6", "5,7",
"5,8", "5,9", "50", "50,1", "50,2", "50,3", "50,4", "50,5", "50,6",
"50,7", "50,8", "50,9", "51", "51,1", "51,2", "51,3", "51,4",
"51,5", "51,6", "51,7", "51,8", "51,9", "52", "52,1", "52,2",
"52,3", "52,4", "52,5", "52,6", "52,7", "52,8", "52,9", "53",
"53,1", "53,2", "53,3", "53,4", "53,5", "53,6", "53,7", "53,8",
"53,9", "54", "54,1", "54,2", "54,3", "54,4", "54,5", "54,6",
"54,7", "54,8", "54,9", "55", "55,1", "55,2", "55,3", "55,4",
"55,5", "55,6", "55,7", "55,8", "55,9", "56", "56,1", "56,2",
"56,3", "56,4", "56,5", "56,6", "56,7", "56,8", "56,9", "57",
"57,1", "57,2", "57,3", "57,4", "57,5", "57,6", "57,7", "57,8",
"57,9", "58", "58,1", "58,2", "58,3", "58,4", "58,5", "58,6",
"58,7", "58,8", "58,9", "59", "59,1", "59,2", "59,3", "59,4",
"59,5", "59,6", "59,7", "59,8", "59,9", "6", "6,1", "6,2", "6,3",
"6,4", "6,5", "6,6", "6,7", "6,8", "6,9", "60", "60,1", "60,2",
"60,3", "60,4", "60,5", "60,6", "60,7", "60,8", "60,9", "61",
"61,1", "61,2", "61,3", "61,4", "61,5", "61,6", "61,7", "61,8",
"61,9", "62", "62,1", "62,2", "62,3", "62,4", "62,5", "62,6",
"62,7", "62,8", "62,9", "63", "63,1", "63,2", "63,3", "63,4",
"63,5", "63,6", "63,7", "63,8", "63,9", "64", "64,1", "64,2",
"64,3", "64,4", "64,5", "64,6", "64,7", "64,8", "64,9", "65",
"65,1", "65,2", "65,3", "65,4", "65,5", "65,6", "65,7", "65,8",
"65,9", "66", "66,1", "66,2", "66,3", "66,4", "66,5", "66,6",
"66,7", "66,8", "66,9", "67", "67,1", "67,2", "67,3", "67,4",
"67,5", "67,6", "67,7", "67,8", "67,9", "68", "68,1", "68,2",
"68,3", "68,4", "68,5", "68,6", "68,7", "68,8", "68,9", "69",
"69,1", "69,2", "69,3", "69,4", "69,5", "69,6", "69,7", "69,8",
"69,9", "7", "7,1", "7,2", "7,3", "7,4", "7,5", "7,6", "7,7",
"7,8", "7,9", "70", "70,1", "70,2", "70,3", "70,4", "70,5", "70,6",
"70,7", "70,8", "70,9", "71", "71,1", "71,2", "71,3", "71,4",
"71,5", "71,6", "71,7", "71,8", "71,9", "72", "72,1", "72,2",
"72,3", "72,4", "72,5", "72,6", "72,7", "72,8", "72,9", "73",
"73,1", "73,2", "73,3", "73,4", "73,5", "73,6", "73,7", "73,8",
"73,9", "74", "74,1", "74,2", "74,3", "74,4", "74,5", "74,6",
"74,7", "74,8", "74,9", "75", "75,1", "75,2", "75,3", "75,4",
"75,5", "75,6", "75,7", "75,8", "75,9", "76", "76,1", "76,2",
"76,3", "76,4", "76,5", "76,6", "76,7", "76,8", "76,9", "77",
"77,1", "77,2", "77,3", "77,4", "77,5", "77,6", "77,7", "77,8",
"77,9", "78", "78,1", "78,2", "78,3", "78,4", "78,5", "78,6",
"78,7", "78,8", "78,9", "79", "79,1", "79,2", "79,3", "79,4",
"79,5", "79,6", "79,7", "79,8", "79,9", "8", "8,1", "8,2", "8,3",
"8,4", "8,5", "8,6", "8,7", "8,8", "8,9", "80", "80,1", "80,2",
"80,3", "80,4", "80,5", "80,6", "80,7", "80,8", "80,9", "81",
"81,1", "81,2", "81,3", "81,4", "81,5", "81,6", "81,7", "81,8",
"81,9", "82", "82,1", "82,2", "82,3", "82,4", "82,5", "82,6",
"82,7", "82,8", "82,9", "83", "83,1", "83,2", "83,3", "83,4",
"83,5", "83,6", "83,7", "83,8", "83,9", "84", "84,1", "84,2",
"84,3", "84,4", "84,5", "84,6", "84,7", "84,8", "84,9", "85",
"85,1", "85,2", "85,3", "85,4", "85,5", "85,6", "85,7", "85,8",
"85,9", "86", "86,1", "86,2", "86,3", "86,4", "86,5", "86,6",
"86,7", "86,8", "86,9", "87", "87,1", "87,2", "87,3", "87,4",
"87,5", "87,6", "87,7", "87,8", "87,9", "88", "88,1", "88,2",
"88,3", "88,4", "88,5", "88,6", "88,7", "88,8", "88,9", "89",
"89,1", "89,2", "89,3", "89,4", "89,5", "89,6", "89,7", "89,8",
"89,9", "9", "9,1", "9,2", "9,3", "9,4", "9,5", "9,6", "9,7",
"9,8", "9,9", "90", "90,1", "90,2", "90,3", "90,4", "90,5", "90,6",
"90,7", "90,8", "90,9", "91", "91,1", "91,2", "91,3", "91,4",
"91,5", "91,6", "91,7", "91,8", "91,9", "92", "92,1", "92,2",
"92,3", "92,4", "92,5", "92,6", "92,7", "92,8", "92,9", "93",
"93,1", "93,2", "93,3", "93,4", "93,5", "93,6", "93,7", "93,8",
"93,9", "94", "94,1", "94,2", "94,3", "94,4", "94,5", "94,6",
"94,7", "94,8", "94,9", "95", "95,1", "95,2", "95,3", "95,4",
"95,5", "95,6", "95,7", "95,8", "95,9", "96", "96,1", "96,2",
"96,3", "96,4", "96,5", "96,6", "96,7", "96,8", "96,9", "97",
"97,1", "97,2", "97,3", "97,4", "97,5", "97,6", "97,7", "97,8",
"97,9", "98", "98,1", "98,2", "98,3", "98,4", "98,5", "98,6",
"98,7", "98,8", "98,9", "99", "99,1", "99,2", "99,3", "99,4",
"99,5", "99,6", "99,7", "99,8", "99,9"), class = "factor"), Pcsge = structure(1:20, .Label = c("0",
"0,1", "0,2", "0,3", "0,4", "0,5", "0,6", "0,7", "0,8", "0,9",
"1", "1,1", "1,2", "1,3", "1,4", "1,5", "1,6", "1,7", "1,8",
"1,9", "10", "10,1", "10,2", "10,3", "10,4", "10,5", "10,6",
"10,7", "10,8", "10,9", "100", "11", "11,1", "11,2", "11,3",
"11,4", "11,5", "11,6", "11,7", "11,8", "11,9", "12", "12,1",
"12,2", "12,3", "12,4", "12,5", "12,6", "12,7", "12,8", "12,9",
"13", "13,1", "13,2", "13,3", "13,4", "13,5", "13,6", "13,7",
"13,8", "13,9", "14", "14,1", "14,2", "14,3", "14,4", "14,5",
"14,6", "14,7", "14,8", "14,9", "15", "15,1", "15,2", "15,3",
"15,4", "15,5", "15,6", "15,7", "15,8", "15,9", "16", "16,1",
"16,2", "16,3", "16,4", "16,5", "16,6", "16,7", "16,8", "16,9",
"17", "17,1", "17,2", "17,3", "17,4", "17,5", "17,6", "17,7",
"17,8", "17,9", "18", "18,1", "18,2", "18,3", "18,4", "18,5",
"18,6", "18,7", "18,8", "18,9", "19", "19,1", "19,2", "19,3",
"19,4", "19,5", "19,6", "19,7", "19,8", "19,9", "2", "2,1", "2,2",
"2,3", "2,4", "2,5", "2,6", "2,7", "2,8", "2,9", "20", "20,1",
"20,2", "20,3", "20,4", "20,5", "20,6", "20,7", "20,8", "20,9",
"21", "21,1", "21,2", "21,3", "21,4", "21,5", "21,6", "21,7",
"21,8", "21,9", "22", "22,1", "22,2", "22,3", "22,4", "22,5",
"22,6", "22,7", "22,8", "22,9", "23", "23,1", "23,2", "23,3",
"23,4", "23,5", "23,6", "23,7", "23,8", "23,9", "24", "24,1",
"24,2", "24,3", "24,4", "24,5", "24,6", "24,7", "24,8", "24,9",
"25", "25,1", "25,2", "25,3", "25,4", "25,5", "25,6", "25,7",
"25,8", "25,9", "26", "26,1", "26,2", "26,3", "26,4", "26,5",
"26,6", "26,7", "26,8", "26,9", "27", "27,1", "27,2", "27,3",
"27,4", "27,5", "27,6", "27,7", "27,8", "27,9", "28", "28,1",
"28,2", "28,3", "28,4", "28,5", "28,6", "28,7", "28,8", "28,9",
"29", "29,1", "29,2", "29,3", "29,4", "29,5", "29,6", "29,7",
"29,8", "29,9", "3", "3,1", "3,2", "3,3", "3,4", "3,5", "3,6",
"3,7", "3,8", "3,9", "30", "30,1", "30,2", "30,3", "30,4", "30,5",
"30,6", "30,7", "30,8", "30,9", "31", "31,1", "31,2", "31,3",
"31,4", "31,5", "31,6", "31,7", "31,8", "31,9", "32", "32,1",
"32,2", "32,3", "32,4", "32,5", "32,6", "32,7", "32,8", "32,9",
"33", "33,1", "33,2", "33,3", "33,4", "33,5", "33,6", "33,7",
"33,8", "33,9", "34", "34,1", "34,2", "34,3", "34,4", "34,5",
"34,6", "34,7", "34,8", "34,9", "35", "35,1", "35,2", "35,3",
"35,4", "35,5", "35,6", "35,7", "35,8", "35,9", "36", "36,1",
"36,2", "36,3", "36,4", "36,5", "36,6", "36,7", "36,8", "36,9",
"37", "37,1", "37,2", "37,3", "37,4", "37,5", "37,6", "37,7",
"37,8", "37,9", "38", "38,1", "38,2", "38,3", "38,4", "38,5",
"38,6", "38,7", "38,8", "38,9", "39", "39,1", "39,2", "39,3",
"39,4", "39,5", "39,6", "39,7", "39,8", "39,9", "4", "4,1", "4,2",
"4,3", "4,4", "4,5", "4,6", "4,7", "4,8", "4,9", "40", "40,1",
"40,2", "40,3", "40,4", "40,5", "40,6", "40,7", "40,8", "40,9",
"41", "41,1", "41,2", "41,3", "41,4", "41,5", "41,6", "41,7",
"41,8", "41,9", "42", "42,1", "42,2", "42,3", "42,4", "42,5",
"42,6", "42,7", "42,8", "42,9", "43", "43,1", "43,2", "43,3",
"43,4", "43,5", "43,6", "43,7", "43,8", "43,9", "44", "44,1",
"44,2", "44,3", "44,4", "44,5", "44,6", "44,7", "44,8", "44,9",
"45", "45,1", "45,2", "45,3", "45,4", "45,5", "45,6", "45,7",
"45,8", "45,9", "46", "46,1", "46,2", "46,3", "46,4", "46,5",
"46,6", "46,7", "46,8", "46,9", "47", "47,1", "47,2", "47,3",
"47,4", "47,5", "47,6", "47,7", "47,8", "47,9", "48", "48,1",
"48,2", "48,3", "48,4", "48,5", "48,6", "48,7", "48,8", "48,9",
"49", "49,1", "49,2", "49,3", "49,4", "49,5", "49,6", "49,7",
"49,8", "49,9", "5", "5,1", "5,2", "5,3", "5,4", "5,5", "5,6",
"5,7", "5,8", "5,9", "50", "50,1", "50,2", "50,3", "50,4", "50,5",
"50,6", "50,7", "50,8", "50,9", "51", "51,1", "51,2", "51,3",
"51,4", "51,5", "51,6", "51,7", "51,8", "51,9", "52", "52,1",
"52,2", "52,3", "52,4", "52,5", "52,6", "52,7", "52,8", "52,9",
"53", "53,1", "53,2", "53,3", "53,4", "53,5", "53,6", "53,7",
"53,8", "53,9", "54", "54,1", "54,2", "54,3", "54,4", "54,5",
"54,6", "54,7", "54,8", "54,9", "55", "55,1", "55,2", "55,3",
"55,4", "55,5", "55,6", "55,7", "55,8", "55,9", "56", "56,1",
"56,2", "56,3", "56,4", "56,5", "56,6", "56,7", "56,8", "56,9",
"57", "57,1", "57,2", "57,3", "57,4", "57,5", "57,6", "57,7",
"57,8", "57,9", "58", "58,1", "58,2", "58,3", "58,4", "58,5",
"58,6", "58,7", "58,8", "58,9", "59", "59,1", "59,2", "59,3",
"59,4", "59,5", "59,6", "59,7", "59,8", "59,9", "6", "6,1", "6,2",
"6,3", "6,4", "6,5", "6,6", "6,7", "6,8", "6,9", "60", "60,1",
"60,2", "60,3", "60,4", "60,5", "60,6", "60,7", "60,8", "60,9",
"61", "61,1", "61,2", "61,3", "61,4", "61,5", "61,6", "61,7",
"61,8", "61,9", "62", "62,1", "62,2", "62,3", "62,4", "62,5",
"62,6", "62,7", "62,8", "62,9", "63", "63,1", "63,2", "63,3",
"63,4", "63,5", "63,6", "63,7", "63,8", "63,9", "64", "64,1",
"64,2", "64,3", "64,4", "64,5", "64,6", "64,7", "64,8", "64,9",
"65", "65,1", "65,2", "65,3", "65,4", "65,5", "65,6", "65,7",
"65,8", "65,9", "66", "66,1", "66,2", "66,3", "66,4", "66,5",
"66,6", "66,7", "66,8", "66,9", "67", "67,1", "67,2", "67,3",
"67,4", "67,5", "67,6", "67,7", "67,8", "67,9", "68", "68,1",
"68,2", "68,3", "68,4", "68,5", "68,6", "68,7", "68,8", "68,9",
"69", "69,1", "69,2", "69,3", "69,4", "69,5", "69,6", "69,7",
"69,8", "69,9", "7", "7,1", "7,2", "7,3", "7,4", "7,5", "7,6",
"7,7", "7,8", "7,9", "70", "70,1", "70,2", "70,3", "70,4", "70,5",
"70,6", "70,7", "70,8", "70,9", "71", "71,1", "71,2", "71,3",
"71,4", "71,5", "71,6", "71,7", "71,8", "71,9", "72", "72,1",
"72,2", "72,3", "72,4", "72,5", "72,6", "72,7", "72,8", "72,9",
"73", "73,1", "73,2", "73,3", "73,4", "73,5", "73,6", "73,7",
"73,8", "73,9", "74", "74,1", "74,2", "74,3", "74,4", "74,5",
"74,6", "74,7", "74,8", "74,9", "75", "75,1", "75,2", "75,3",
"75,4", "75,5", "75,6", "75,7", "75,8", "75,9", "76", "76,1",
"76,2", "76,3", "76,4", "76,5", "76,6", "76,7", "76,8", "76,9",
"77", "77,1", "77,2", "77,3", "77,4", "77,5", "77,6", "77,7",
"77,8", "77,9", "78", "78,1", "78,2", "78,3", "78,4", "78,5",
"78,6", "78,7", "78,8", "78,9", "79", "79,1", "79,2", "79,3",
"79,4", "79,5", "79,6", "79,7", "79,8", "79,9", "8", "8,1", "8,2",
"8,3", "8,4", "8,5", "8,6", "8,7", "8,8", "8,9", "80", "80,1",
"80,2", "80,3", "80,4", "80,5", "80,6", "80,7", "80,8", "80,9",
"81", "81,1", "81,2", "81,3", "81,4", "81,5", "81,6", "81,7",
"81,8", "81,9", "82", "82,1", "82,2", "82,3", "82,4", "82,5",
"82,6", "82,7", "82,8", "82,9", "83", "83,1", "83,2", "83,3",
"83,4", "83,5", "83,6", "83,7", "83,8", "83,9", "84", "84,1",
"84,2", "84,3", "84,4", "84,5", "84,6", "84,7", "84,8", "84,9",
"85", "85,1", "85,2", "85,3", "85,4", "85,5", "85,6", "85,7",
"85,8", "85,9", "86", "86,1", "86,2", "86,3", "86,4", "86,5",
"86,6", "86,7", "86,8", "86,9", "87", "87,1", "87,2", "87,3",
"87,4", "87,5", "87,6", "87,7", "87,8", "87,9", "88", "88,1",
"88,2", "88,3", "88,4", "88,5", "88,6", "88,7", "88,8", "88,9",
"89", "89,1", "89,2", "89,3", "89,4", "89,5", "89,6", "89,7",
"89,8", "89,9", "9", "9,1", "9,2", "9,3", "9,4", "9,5", "9,6",
"9,7", "9,8", "9,9", "90", "90,1", "90,2", "90,3", "90,4", "90,5",
"90,6", "90,7", "90,8", "90,9", "91", "91,1", "91,2", "91,3",
"91,4", "91,5", "91,6", "91,7", "91,8", "91,9", "92", "92,1",
"92,2", "92,3", "92,4", "92,5", "92,6", "92,7", "92,8", "92,9",
"93", "93,1", "93,2", "93,3", "93,4", "93,5", "93,6", "93,7",
"93,8", "93,9", "94", "94,1", "94,2", "94,3", "94,4", "94,5",
"94,6", "94,7", "94,8", "94,9", "95", "95,1", "95,2", "95,3",
"95,4", "95,5", "95,6", "95,7", "95,8", "95,9", "96", "96,1",
"96,2", "96,3", "96,4", "96,5", "96,6", "96,7", "96,8", "96,9",
"97", "97,1", "97,2", "97,3", "97,4", "97,5", "97,6", "97,7",
"97,8", "97,9", "98", "98,1", "98,2", "98,3", "98,4", "98,5",
"98,6", "98,7", "98,8", "98,9", "99", "99,1", "99,2", "99,3",
"99,4", "99,5", "99,6", "99,7", "99,8", "99,9"), class = "factor")), row.names = c(NA,
20L), class = "data.frame")
At first, I though it was a problem with class of variables (numeric, factor...) but even when I convert to numeric it doesnt work...
Data$Pmanche <- levels(Data$Pmanche)[Data$Pmanche]
Data$Pcsge <- levels(Data$Pcsge)[Data$Pcsge]
Thanks for your time!
Here is my code:
## definition workdirectory
setwd(dir="C:/Users/F596028/Documents/nouveau dossier/Optimisation")
##############################
# Packages #
##############################
# Graphics
#install.packages("ggplot2")
library(ggplot2)
##############################
# ouverture du fichier Excel #
##############################
## Fichiers extension .csv du repertoir
files <- list.files(pattern = "\\.csv$")
files <- sort(files)
## Enregistrement des titres
headers <- read.csv("Classeur1.csv", header = F, nrows = 1, as.is = T, sep=";")
## Enregistrement des données
Sub1 <- read.csv(files, skip=1, header=F, sep=";")
colnames(Sub1)=headers
Pmanche<-Sub1[,c(3)]
Pcsge<-Sub1[,c(4)]
Data <- data.frame(Pmanche,Pcsge)
##############################
# Plots #
##############################
#Data$Pmanche <- levels(Data$Pmanche)[Data$Pmanche]
#Data$Pcsge <- levels(Data$Pcsge)[Data$Pcsge]
p<- ggplot(Data, aes(Pmanche,Pcsge))
p + geom_point() + scale_x_continuous(breaks=1:10)
Ok, I solved it.
The problem was the data source.
I learned we need to be careful when taking data from excel... Decimals must be indicated with "." and not ","
Thanks

Replace value with NULL in column [duplicate]

This question already has an answer here:
Set NA and "" Cells in R Dataframe to NULL
(1 answer)
Closed 4 years ago.
I have a dataframe where I want to replace all values in a column that contain the value '2018' with NULL.
I have a dataset where every value in a column is a list. There are NULLs included as well. One of the values is not a list and I want to replace it with a NULL. If I replace it with NA then the datatypes in that column are mixed.
If I have a column like below, how do I replace the value containing 2018 with NULL instead of NA?
spend actions
176.2 2018-02-24
166.66 list(action_type = c("landing_page_view", "link_click", "offsit...
153.89 list(action_type = c("landing_page_view", "like", "link_click",...
156.54 list(action_type = c("landing_page_view", "like", "link_click",...
254.95 list(action_type = c("landing_page_view", "like", "link_click",...
374 list(action_type = c("landing_page_view", "like", "link_click",...
353.29 list(action_type = c("landing_page_view", "like", "link_click",...
0.41 NULL
Reproducible Example:
structure(list(spend = c("176.2", "166.66", "153.89", "156.54",
"254.95", "374", "353.29", "0.41"), actions = list("2018-02-24",
structure(list(action_type = c("landing_page_view", "link_click",
"offsite_conversion.fb_pixel_add_to_cart",
"offsite_conversion.fb_pixel_purchase",
"offsite_conversion.fb_pixel_search",
"offsite_conversion.fb_pixel_view_content",
"post", "post_reaction", "page_engagement", "post_engagement",
"offsite_conversion"), value = c("179", "275", "212", "18",
"269", "1434", "1", "17", "293", "293", "1933")), .Names = c("action_type",
"value"), class = "data.frame", row.names = c(NA, 11L)),
structure(list(action_type = c("landing_page_view", "like",
"link_click", "offsite_conversion.fb_pixel_add_to_cart",
"offsite_conversion.fb_pixel_purchase",
"offsite_conversion.fb_pixel_search",
"offsite_conversion.fb_pixel_view_content", "post_reaction",
"page_engagement", "post_engagement", "offsite_conversion"
), value = c("136", "3", "248", "101", "6", "237", "730",
"11", "262", "259", "1074")), .Names = c("action_type", "value"
), class = "data.frame", row.names = c(NA, 11L)), structure(list(
action_type = c("landing_page_view", "like", "link_click",
"offsite_conversion.fb_pixel_add_to_cart",
"offsite_conversion.fb_pixel_purchase",
"offsite_conversion.fb_pixel_search",
"offsite_conversion.fb_pixel_view_content",
"post", "post_reaction", "page_engagement", "post_engagement",
"offsite_conversion"), value = c("95", "1", "156", "91",
"5", "83", "532", "1", "13", "171", "170", "711")), .Names =
c("action_type",
"value"), class = "data.frame", row.names = c(NA, 12L)),
structure(list(action_type = c("landing_page_view", "like",
"link_click", "offsite_conversion.fb_pixel_add_to_cart",
"offsite_conversion.fb_pixel_purchase",
"offsite_conversion.fb_pixel_search",
"offsite_conversion.fb_pixel_view_content", "post_reaction",
"page_engagement", "post_engagement", "offsite_conversion"
), value = c("178", "4", "243", "56", "4", "138", "437",
"19", "266", "262", "635")), .Names = c("action_type", "value"
), class = "data.frame", row.names = c(NA, 11L)), structure(list(
action_type = c("landing_page_view", "like", "link_click",
"offsite_conversion.fb_pixel_add_to_cart",
"offsite_conversion.fb_pixel_purchase",
"offsite_conversion.fb_pixel_search",
"offsite_conversion.fb_pixel_view_content",
"post_reaction", "page_engagement", "post_engagement",
"offsite_conversion"), value = c("203", "2", "306", "105",
"7", "186", "954", "23", "331", "329", "1252")), .Names =
c("action_type",
"value"), class = "data.frame", row.names = c(NA, 11L)),
structure(list(action_type = c("landing_page_view", "like",
"link_click", "offsite_conversion.fb_pixel_add_to_cart",
"offsite_conversion.fb_pixel_purchase",
"offsite_conversion.fb_pixel_search",
"offsite_conversion.fb_pixel_view_content", "post", "post_reaction",
"page_engagement", "post_engagement", "offsite_conversion"
), value = c("241", "4", "320", "106", "3", "240", "789",
"1", "17", "342", "338", "1138")), .Names = c("action_type",
"value"), class = "data.frame", row.names = c(NA, 12L)),
NULL)), .Names = c("spend", "actions"), row.names = c(NA,
-8L), class = "data.frame")
My ultimate goal is to use this function with this dataset to make the action_types their own column. This function works when either a list or NULL is in the actions column:
fb_insights_all<-df %>%
as.tibble() %>%
filter(!map_lgl(actions, is.null)) %>%
unnest() %>%
right_join(select(df, -actions)) %>%
spread(action_type, value)
Error: Each column must either be a list of vectors or a list of data frames [actions]
Without data to test this on, I'd try:
df$COL1<-ifelse(grepl("2018", df$COL1),"NULL",df$COL1)
As stated here NA functions more like what you seem to be trying to do, while NULL serves a different function. If you just want the value to just say "NULL" rather than function like NULL, treat it like a character value.

Anova loop in R

Im currently making a lot of ANOVA's in R and my code looks like this:
My data looks like this:
structure(list(Vial_nr = c(151L, 151L, 151L, 162L), Concentration = structure(c(1L,
1L, 1L, 1L), .Label = c("a", "b", "c", "d", "e", "x", "y"), class = "factor"),
Line = structure(c(1L, 1L, 1L, 1L), .Label = c("20", "23",
"40", "73"), class = "factor"), Sex = structure(c(1L, 1L,
1L, 1L), .Label = c("f", "m"), class = "factor"), Fly = structure(c(1L,
2L, 3L, 1L), .Label = c("1", "2", "3"), class = "factor"),
Temp = structure(c(1L, 1L, 1L, 1L), .Label = c("23", "29"
), class = "factor"), X0.5_sec = c(51.84, 41.28, 8.64, 28.8
), X1_sec = c(41.76, 8.64, 10.56, 42.72), X1.5_sec = c(42.72,
17.28, 10.08, 57.12), X2_sec = c(51.36, 29.76, 19.68, 71.52
), X2.5_sec = c(52.8, 44.64, 39.36, 69.12), X3_sec = c(55.68,
52.8, 58.08, 82.56), Vial = structure(c(138L, 138L, 138L,
149L), .Label = 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",
"40", "41", "42", "43", "47", "49", "50", "56", "57", "59",
"61", "62", "63", "64", "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",
"201", "202", "203", "204", "205", "206", "207", "208", "209",
"210", "211", "212", "213", "214", "215", "216", "217", "218",
"219", "220", "221", "222", "223", "224", "225", "226", "227",
"228", "229", "230", "231", "232", "233", "234", "235", "236",
"237", "238", "239", "240", "241", "242", "243", "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", "273",
"274", "275", "276", "277", "278", "279", "280", "461", "462",
"463", "464", "465", "466", "467", "468", "469", "470", "471",
"472", "473", "474", "475", "476", "477", "478", "479", "480",
"481", "482", "483", "484", "485", "486", "487", "488", "489",
"490", "491", "492", "493", "494", "495", "496", "497", "498",
"499", "500", "501", "502", "503", "504", "505", "506", "507",
"508", "509", "510", "511", "512", "513", "514", "515", "516",
"517", "518", "519", "520", "521", "522", "523", "524", "525",
"526", "527", "528", "529", "530", "531", "532", "533", "534",
"535", "536", "537", "538", "539", "540", "541", "542", "543",
"544", "545", "546", "547", "548", "549", "550"), class = "factor")), .Names = c("Vial_nr",
"Concentration", "Line", "Sex", "Fly", "Temp", "X0.5_sec", "X1_sec",
"X1.5_sec", "X2_sec", "X2.5_sec", "X3_sec", "Vial"), row.names = 4:7, class = "data.frame")
dat <- read.table("Complete RING.txt", header =TRUE)
str(dat)
dat$Vial <- as.factor(dat$Vial)
dat$Line <- as.factor(dat$Line)
dat$Fly <- as.factor(dat$Fly)
dat$Temp <- as.factor(dat$Temp)
str(dat)
Line20af <- subset(dat, Line=="20" & Concentration=="a" & Sex=="f")
Line20bf <- subset(dat, Line=="20" & Concentration=="b" & Sex=="f")
Line20cf <- subset(dat, Line=="20" & Concentration=="c" & Sex=="f")
Line20df <- subset(dat, Line=="20" & Concentration=="d" & Sex=="f")
Line20ef <- subset(dat, Line=="20" & Concentration=="e" & Sex=="f")
Line20xf <- subset(dat, Line=="20" & Concentration=="x" & Sex=="f")
Line20yf <- subset(dat, Line=="20" & Concentration=="y" & Sex=="f")
out20 <- matrix(ncol=6, nrow=7)
colnames(out20) <- colnames(Line20af)[7:12]
rownames(out20) <- paste0("Concentration", 1:7)
for(i in 1:6){
tmp <- data.frame(Line20af[,6+i],Line20af$Temp)
colnames(tmp)<-c("y","c")
fit1=lm(y~c,data=tmp)
fit2=lm(y~1,data=tmp)
out20[1,i]<-anova(fit1,fit2)$"Pr(>F)"[2]
tmp <- data.frame(Line20bf[,6+i],Line20bf$Temp)
colnames(tmp)<-c("y","c")
fit1=lm(y~c,data=tmp)
fit2=lm(y~1,data=tmp)
out20[2,i]<-anova(fit1,fit2)$"Pr(>F)"[2]
tmp <- data.frame(Line20cf[,6+i],Line20cf$Temp)
colnames(tmp)<-c("y","c")
fit1=lm(y~c,data=tmp)
fit2=lm(y~1,data=tmp)
out20[3,i]<-anova(fit1,fit2)$"Pr(>F)"[2]
tmp <- data.frame(Line20df[,6+i],Line20df$Temp)
colnames(tmp)<-c("y","c")
fit1=lm(y~c,data=tmp)
fit2=lm(y~1,data=tmp)
out20[4,i]<-anova(fit1,fit2)$"Pr(>F)"[2]
tmp <- data.frame(Line20ef[,6+i],Line20ef$Temp)
colnames(tmp)<-c("y","c")
fit1=lm(y~c,data=tmp)
fit2=lm(y~1,data=tmp)
out20[5,i]<-anova(fit1,fit2)$"Pr(>F)"[2]
tmp <- data.frame(Line20xf[,6+i],Line20xf$Temp)
colnames(tmp)<-c("y","c")
fit1=lm(y~c,data=tmp)
fit2=lm(y~1,data=tmp)
out20[6,i]<-anova(fit1,fit2)$"Pr(>F)"[2]
tmp <- data.frame(Line20yf[,6+i],Line20yf$Temp)
colnames(tmp)<-c("y","c")
fit1=lm(y~c,data=tmp)
fit2=lm(y~1,data=tmp)
out20[7,i]<-anova(fit1,fit2)$"Pr(>F)"[2]
}
xtable(out20)
But doing this a lot of times just copy paste seems really dumb, i have tried to make temp data fields so i dont get to many datasets, however that doesn't yield any results. I have also tried to make a for loop using unique() on Concentration to make create the new datasets but then R doesn't print any results. Is there a way to optimize this piece of script to streamline my workflow and not overflow my workspace?
EDIT: added dput of data snip

combine two data frames into one while keeping the original row numbers

I'm struggling with a very simple problem. I have two data frames to be combined into a single data frame while retaining their original row names. If you're interested to play with the two data frames:
> dput(cc)
structure(list(c = c(166.081273211195, 117.874627144804, 85.7050194973198,
122.960746859139, 144.149802403233, 90.8034500957001, 89.5265981283352,
77.8535718910714, 144.544005656701, 115.597165020403, 109.028391182666,
89.4045716355402, 77.7944830105746, 69.3378920684953, 79.9094499459695,
146.768077595585, 157.933946809176, 92.562729606313, 62.5081476457419,
90.1081848285295, 111.830482369239, 111.596975757741, 99.2311075024839,
145.204385556523, 99.0215341758211, 75.4302512245677, 92.0094563363458,
77.7314808830408)), .Names = "c", row.names = c("26", "27", "28",
"29", "35", "36", "37", "38", "39", "40", "46", "47", "48", "49",
"50", "51", "52", "56", "57", "58", "59", "60", "61", "62", "69",
"70", "71", "72"), class = "data.frame")
> dput(ccc)
structure(list(b = c(76.376257255471, 61.8314936138378, 62.769450181685,
73.6356164203567, 111.690756826382, 76.9294523843767, 61.3534699857719,
69.3647221333577, 83.9764878084258, 81.3800252294203, 69.5091780233591,
87.3595961209547, 78.5074999563006, 74.4479256924594, 81.5920316281566,
96.3417259554163, 75.4138056616399, 76.0553034201146, 95.1759950844736,
81.3252467041995, 86.306305649635, 70.5626459312969, 72.7797520793756,
119.49702877934, 123.268678343102, 88.0450051118928, 76.2139948860248,
98.1496728839206, 126.396927030103, 146.058540478643, 115.7341525964,
87.280600158726, 78.0274068331766, 122.817977752389, 142.491559175427,
152.895839114334, 94.4932174696818, 117.167042165763, 85.5340971715004,
101.480170738897, 117.759691799033, 128.998051359269, 98.3180491401911,
84.5915489017958, 87.4927520958843, 75.5366495973031, 118.088343275321,
121.375320935357, 94.7724147096235, 70.2266610201599, 123.158462686523,
76.87408931845, 94.4365460662552, 105.952134808703, 76.821070196668
)), .Names = "b", row.names = 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", "30", "31", "32",
"33", "34", "41", "42", "43", "44", "45", "53", "54", "55", "63",
"64", "65", "66", "67", "68", "73", "74", "75", "76", "77", "78",
"79", "80", "81", "82", "83"), class = "data.frame")
The easiest way to combine is
> c(cc$c, ccc$b)
[1] 166.08127 117.87463 85.70502 122.96075 144.14980 90.80345 89.52660 77.85357 144.54401
[10] 115.59717 109.02839 89.40457 77.79448 69.33789 79.90945 146.76808 157.93395 92.56273
[19] 62.50815 90.10818 111.83048 111.59698 99.23111 145.20439 99.02153 75.43025 92.00946
[28] 77.73148 76.37626 61.83149 62.76945 73.63562 111.69076 76.92945 61.35347 69.36472
[37] 83.97649 81.38003 69.50918 87.35960 78.50750 74.44793 81.59203 96.34173 75.41381
[46] 76.05530 95.17600 81.32525 86.30631 70.56265 72.77975 119.49703 123.26868 88.04501
[55] 76.21399 98.14967 126.39693 146.05854 115.73415 87.28060 78.02741 122.81798 142.49156
[64] 152.89584 94.49322 117.16704 85.53410 101.48017 117.75969 128.99805 98.31805 84.59155
[73] 87.49275 75.53665 118.08834 121.37532 94.77241 70.22666 123.15846 76.87409 94.43655
[82] 105.95213 76.82107
But doing this recreate the row numbers. Is there any simple function to combine while keeping the row names intact? Thanks!
These lines of code should solve the problem
z0 <- as.numeric(c(rownames(cc), rownames(ccc)))
z <- data.frame(c(cc$c, ccc$b))
row.names(z) <- z0
data.frame(z[order(as.numeric(row.names(z))),])

Resources