getting error in dataframe replacement has 0 data has x - r

out <-diallele1(dataframe = fulldial, male = "MALE", female = "FEMALE",
progeny = "TRT", replication = "REP", yvar = "YIELD" )
structure(list(FAMILY = c(1, 1, 1, 2, 2, 2), TRT = c(11, 11,
11, 12, 12, 12), FAMQC = c(NA, NA, NA, 1, 1, 1), MALE = c(1,
1, 1, 1, 1, 1), FEMALE = c(1, 1, 1, 2, 2, 2), REP = c(1, 2, 3,
1, 2, 3), AUDPC = c(3116.66666666667, 2983.33333333333, 3050,
2483.33333333333, 1883.33333333333, 2183.33333333333)), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
while running these command i am getting the following error
Error in `$<-.data.frame`(`*tmp*`, "male", value = integer(0)) :
replacement has 0 rows, data has 192
somebody help me to fix this
thankyou

Related

R error: Error in UseMethod("weekdays") : no applicable method for 'weekdays' applied to an object of class "character"

Ive tried creating a day of week variable using this code:
weekdays1 <- c('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday')
fulldata$wDay <- factor((weekdays(fulldata$completed_ts) %in% weekdays1),
levels=c(FALSE, TRUE), labels=c('weekend', 'weekday'))
# Error message:
# Error in UseMethod("weekdays") :
# no applicable method for 'weekdays' applied to an object of class "character"
This issue arises only after adding a new variable (coded on SPSS) to the data file, and resolves when removing this added variable (however I need this variable in my analyses) Unsure why this is the case.
Any suggestions would be really appreciated, cheers.
structure(list(participant_id = c(5237430, 5237430, 5237430),
participant_tz = c("UTC", "Australia/Melbourne", "Australia/Melbourne"
), study_id = c("s4lpHqswe", "s4lpHqswe", "s4lpHqswe"), study_name = c("Social Networks and Eating Behaviours",
"Social Networks and Eating Behaviours", "Social Networks and Eating Behaviours"
), study_version = c(7, 7, 7), survey_id = c("X81ypVgkcU",
"X81ypVgkcU", "X81ypVgkcU"), survey_name = c("Survey 1",
"Survey 1", "Survey 1"), trigger = c("scheduled", "scheduled",
"scheduled"), export_tz = c("Australia/Melbourne", "Australia/Melbourne",
"Australia/Melbourne"), start_end = c(1, 1, 1), created_ts = structure(c(1587937200,
1587813720, 1587820680), tzone = "UTC", class = c("POSIXct",
"POSIXt")), scheduled_ts = structure(c(1587935280, 1587813720,
1587820680), tzone = "UTC", class = c("POSIXct", "POSIXt"
)), started_ts = c("#NULL!", "43946.473611111112", "43946.554166666669"
), completed_ts = c(NA, 43946.4743055556, 43946.5548611111
), expired_ts = c("43947.901388888888", "#NULL!", "#NULL!"
), uploaded_ts = c("#NULL!", "43946.474305555574", "43946.554861111101"
), total_rt = c("NA", "56500", "33155"), rand_prob = c("NA",
"NA", "NA"), lonely1 = c(NA, 6, 5), lonely1_rt = c(NA, 4359,
1377), happy = c(NA, 5, 5), happy_rt = c(NA, 1071, 963),
lonely2 = c(NA, 4, 3), lonely2_rt = c(NA, 979, 2319), pos_feedback_1 = c(NA,
1, 1), pos_feedback_2 = c(NA, 0, 0), pos_feedback_3 = c(NA,
0, 0), pos_feedback_4 = c(NA, 0, 0), pos_feedback_5 = c(NA,
0, 0), pos_feedback_rt = c(NA, 7452, 1650), neg_feedback_1 = c(NA,
1, 1), neg_feedback_2 = c(NA, 0, 0), neg_feedback_3 = c(NA,
0, 0), neg_feedback_4 = c(NA, 0, 0), neg_feedback_5 = c(NA,
0, 0), neg_feedback_rt = c(NA, 2695, 3267), sat1 = c(NA,
4, 2), sat1_rt = c(NA, 3462, 1482), sat2 = c(NA, 5, 5), sat2_rt = c(NA,
1330, 948), comp1 = c(NA, 5, 4), comp1_rt = c(NA, 1043, 926
), comp2 = c(NA, 3, 3), comp2_rt = c(NA, 1134, 851), comp3 = c(NA,
2, 2), comp3_rt = c(NA, 2985, 2888), comp4 = c(NA, 6, 5),
comp4_rt = c(NA, 2221, 1253), selfie1 = c(NA, 1, 1), selfie1_rt = c(NA,
2315, 1241), selfie2 = c(NA, 102, 78), selfie2_rt = c(NA,
1393, 1078), selfie3 = c(NA, 1, 2), selfie3_rt = c(NA, 2589,
883), inspo1 = c(NA, 1, 2), inspo1_rt = c(NA, 1641, 788),
inspo2 = c(NA, 1, 2), inspo2_rt = c(NA, 1435, 968), inspo3 = c(NA,
2, 2), inspo3_rt = c(NA, 3953, 883), dating1 = structure(c(NA,
1L, 2L), .Label = c("1", "2"), class = "factor"), dating1_rt = c(NA,
2710, 1064), dating2_1 = c(NA, 0, NA), dating2_2 = c(NA,
1, NA), dating2_3 = c(NA, 0, NA), dating2_4 = c(NA, 0, NA
), dating2_5 = c(NA, 1, NA), dating2_6 = c(NA, 0, NA), dating2_7 = c(NA,
0, NA), dating2_rt = c(NA, 3988, NA), video = c(NA, 2, 2),
video_rt = c(NA, 2809, 1283), eating_1 = c(NA, 1, 0), eating_2 = c(NA,
0, 0), eating_3 = c(NA, 0, 0), eating_4 = c(NA, 0, 0), eating_5 = c(NA,
0, 0), eating_6 = c(NA, 0, 1), eating_7 = c(NA, 0, 0), eating_8 = c(NA,
0, 0), eating_none = c(NA, 0, 0), eating_rt = c(NA, 2226,
5979), dating = c(NA, 1, 2), dating_rt = c(NA, 2710, 1064
), partner_cat = c(NA_real_, NA_real_, NA_real_), partnerideal_dum = structure(c(NA,
1L, NA), .Label = c("0", "1"), class = "factor"), partnernonideal_dum = structure(c(NA,
1L, NA), .Label = c("0", "1"), class = "factor"), partnerboth_dum = structure(c(NA,
2L, NA), .Label = c("0", "1"), class = "factor"), qualtrics_sample = c(NA_character_,
NA_character_, NA_character_), start_date = structure(c(1587397597,
1587397597, 1587397597), tzone = "UTC", class = c("POSIXct",
"POSIXt")), end_date = structure(c(1587398241, 1587398241,
1587398241), tzone = "UTC", class = c("POSIXct", "POSIXt"
)), status = c(0, 0, 0), ip_address = c("101.182.17.165",
"101.182.17.165", "101.182.17.165"), progress = c(100, 100,
100), duration_in_seconds = c(644, 644, 644), finished = c(1,
1, 1), recorded_date = structure(c(1587398242, 1587398242,
1587398242), tzone = "UTC", class = c("POSIXct", "POSIXt"
)), response_id = c("R_3n97cmY4P1NXi92", "R_3n97cmY4P1NXi92",
"R_3n97cmY4P1NXi92"), user_language = c("EN", "EN", "EN"),
self_genid = c(NA_character_, NA_character_, NA_character_
), agree_share_email = c(1, 1, 1), consent = c(1, 1, 1),
age = c(20, 20, 20), gender = c(2, 2, 2), gender_other = c(NA_character_,
NA_character_, NA_character_), currentweight = c(55, 55,
55), currentheight = c(158, 158, 158), highestweight = c("63",
"63", "63"), highestheight = c("158", "158", "158"), lowestweight = c("55",
"55", "55"), lowestheight = c("158", "158", "158"), culture = c("southern asian",
"southern asian", "southern asian"), culture_other = c(NA_character_,
NA_character_, NA_character_), student = c("yes", "yes",
"yes"), international_student = c(NA_character_, NA_character_,
NA_character_), aus_international_student = c(NA_character_,
NA_character_, NA_character_), aus_years = c(NA_character_,
NA_character_, NA_character_), currentlive = c(NA_character_,
NA_character_, NA_character_), language = c("English", "English",
"English"), language_other = c(NA_character_, NA_character_,
NA_character_), maritalstatus = c("single", "single", "single"
), sexualorientation = c("heterosexual", "heterosexual",
"heterosexual"), sexualorientation_other = c(NA_character_,
NA_character_, NA_character_), education = c("bachelor degree",
"bachelor degree", "bachelor degree"), working_full = c(0,
0, 0), working_part = c(0, 0, 0), working_casual = c(0, 0,
0), working_unemployed = c(0, 0, 0), working_student = c(1,
1, 1), workhours = c("0", "0", "0"), taxes = c(4, 4, 4),
videoconferencing = c(1, 1, 1), zoom = c(1, 1, 1), team_viewer = c(NA_real_,
NA_real_, NA_real_), microsoft_teams = c(NA_real_, NA_real_,
NA_real_), skype = c(NA_real_, NA_real_, NA_real_), webex = c(NA_real_,
NA_real_, NA_real_), googlemeet = c(NA_real_, NA_real_, NA_real_
), joinme = c(NA, NA, NA), whats_app = c(NA_real_, NA_real_,
NA_real_), slack = c(NA_real_, NA_real_, NA_real_), houseparty = c(NA_real_,
NA_real_, NA_real_), videoconferencing_other = c(NA_real_,
NA_real_, NA_real_), videoconferencing_othertext = c(NA_character_,
NA_character_, NA_character_), videoconf_time = c(2, 2, 2
), fooddelivery = c(2, 2, 2), uber_eats = c(NA_real_, NA_real_,
NA_real_), deliveroo = c(NA_real_, NA_real_, NA_real_), menulog = c(NA_real_,
NA_real_, NA_real_), foodora = c(NA_real_, NA_real_, NA_real_
), door_dash = c(NA_real_, NA_real_, NA_real_), fooddelivery_other = c(NA_real_,
NA_real_, NA_real_), fooddelivery_othertext = c(NA_character_,
NA_character_, NA_character_), fooddeliverymonth = c(NA_real_,
NA_real_, NA_real_), serviceson = c(NA_real_, NA_real_, NA_real_
), serviceswith = c(NA_real_, NA_real_, NA_real_), fooddelivery_money = c(NA_real_,
NA_real_, NA_real_), facebook = c(1, 1, 1), instagram = c(1,
1, 1), snapchat = c(1, 1, 1), twitter = c(NA_real_, NA_real_,
NA_real_), tumblr = c(NA_real_, NA_real_, NA_real_), socialmedia_other = c(NA_real_,
NA_real_, NA_real_), socialmedia_othertext = c(NA_character_,
NA_character_, NA_character_), socialmediatime = c(1, 1,
1), socialmediaminutes_t = c("30", "30", "30"), socialmediaminutes_d = c("300",
"300", "300"), selfies = c(4, 4, 4), modifiedselfie = c(1,
1, 1), fitspiration = c(1, 1, 1), fitspirationtime = c(1,
1, 1), thinspiration = c(1, 1, 1), thinspirationtime = c(1,
1, 1), fatspiration = c(1, 1, 1), fatspirationtime = c(2,
2, 2), datingapp = c(1, 1, 1), tinder = c(1, 1, 1), hinge = c(NA_real_,
NA_real_, NA_real_), grindr = c(NA_real_, NA_real_, NA_real_
), bumble = c(NA_real_, NA_real_, NA_real_), ok_cupid = c(NA_real_,
NA_real_, NA_real_), her = c(NA_real_, NA_real_, NA_real_
), offee_meets = c(NA_real_, NA_real_, NA_real_), happn = c(NA_real_,
NA_real_, NA_real_), momo = c(NA_real_, NA_real_, NA_real_
), tantan = c(NA_real_, NA_real_, NA_real_), datingapp_other = c(NA_real_,
NA_real_, NA_real_), datingapp_other_t = c(NA_character_,
NA_character_, NA_character_), datingapp_time = c("multiple times a month",
"multiple times a month", "multiple times a month"), matchweek = c("10",
"10", "10"), match_month = c("40", "40", "40"), date_love = c(1,
1, 1), date_sex = c(1, 1, 1), date_comm = c(1, 1, 1), date_worth = c(NA_real_,
NA_real_, NA_real_), date_thrill = c(1, 1, 1), date_trend = c(NA_real_,
NA_real_, NA_real_), feat_thin = c(NA_real_, NA_real_, NA_real_
), feat_muscle = c(1, 1, 1), feat_face = c(1, 1, 1), feat_sex = c(NA_real_,
NA_real_, NA_real_), feat_health = c(1, 1, 1), feat_intell = c(1,
1, 1), feat_other = c(NA_real_, NA_real_, NA_real_), feat_other_t = c(NA_character_,
NA_character_, NA_character_), covid_food = c(1, 1, 1), covid_apps = c(3,
3, 3), covid_social = c(5, 5, 5), eatingdisorder_diagnosed = c("no",
"no", "no"), month_diagnosed = c(NA_character_, NA_character_,
NA_character_), year_diagnosed = c(NA_character_, NA_character_,
NA_character_), eatingdisorder = c(NA_real_, NA_real_, NA_real_
), eatingdisorder_other = c(NA_character_, NA_character_,
NA_character_), eatingdisorder_status = c(NA_real_, NA_real_,
NA_real_), ed_age = c(NA_character_, NA_character_, NA_character_
), ed_years = c(NA_character_, NA_character_, NA_character_
), socio_1 = c(3, 3, 3), socio_2 = c(4, 4, 4), socio_3 = c(4,
4, 4), socio_4 = c(3, 3, 3), socio_5 = c(2, 2, 2), socio_6 = c(4,
4, 4), socio_7 = c(5, 5, 5), socio_8 = c(5, 5, 5), socio_9 = c(4,
4, 4), socio_10 = c(1, 1, 1), bodysat_1 = c(6, 6, 6), bodysat_2 = c(6,
6, 6), bodysat_3 = c(4, 4, 4), bodysat_4 = c(6, 6, 6), bodysat_5 = c(6,
6, 6), bodysat_6 = c(6, 6, 6), bodysat_7 = c(6, 6, 6), bodysat_8 = c(6,
6, 6), bodyimage_1 = c(5, 5, 5), bodayimage_2 = c(5, 5, 5
), bodyimage_3 = c(5, 5, 5), bodyimage_4 = c(5, 5, 5), bodayimage_5 = c(5,
5, 5), bodayimage_6 = c(5, 5, 5), bodyimage_7 = c(5, 5, 5
), bodyimage_8 = c(5, 5, 5), bodyimage_9 = c(5, 5, 5), bodyimage_10 = c(5,
5, 5), media_1 = c(2, 2, 2), media_2 = c(1, 1, 1), media_3 = c(3,
3, 3), media_4 = c(1, 1, 1), media_5 = c(2, 2, 2), media_6 = c(3,
3, 3), critical_1 = c(4, 4, 4), critical_2 = c(4, 4, 4),
critical_3 = c(4, 4, 4), critical_4 = c(3, 3, 3), critical_5 = c(4,
4, 4), intro_aware_1 = c(2, 2, 2), intro_aware_2 = c(3, 3,
3), intro_aware_3 = c(3, 3, 3), intro_aware_4 = c(3, 3, 3
), cesd_1 = c(2, 2, 2), cesd_2 = c(2, 2, 2), cesd_3 = c(3,
3, 3), cesd_4 = c(3, 3, 3), cesd_5 = c(3, 3, 3), cesd_6 = c(2,
2, 2), cesd_7 = c(2, 2, 2), cesd_8 = c(3, 3, 3), cesd_9 = c(3,
3, 3), cesd_10 = c(2, 2, 2), eat26_1 = c(1, 1, 1), eat26_2 = c(5,
5, 5), eat26_3 = c(1, 1, 1), eat26_4 = c(1, 1, 1), eat26_5 = c(1,
1, 1), eat26_6 = c(1, 1, 1), eat26_7 = c(1, 1, 1), eat26_8 = c(4,
4, 4), eat26_9 = c(6, 6, 6), eat26_10 = c(2, 2, 2), eat26_11 = c(1,
1, 1), eat26_12 = c(1, 1, 1), eat26_13 = c(5, 5, 5), eat26_14 = c(2,
2, 2), eat26_15 = c(5, 5, 5), eat26_16 = c(3, 3, 3), eat26_17 = c(2,
2, 2), eat26_18 = c(2, 2, 2), eat26_19 = c(2, 2, 2), eat26_20 = c(4,
4, 4), eat26_21 = c(1, 1, 1), eat26_22 = c(1, 1, 1), eat26_23 = c(2,
2, 2), eat26_24 = c(2, 2, 2), eat26_25 = c(1, 1, 1), eat26_26 = c(2,
2, 2), eat26_a = c(2, 2, 2), eat26_b = c(2, 2, 2), eat26_c = c(1,
1, 1), eat26_d = c(1, 1, 1), eat26_e = c(1, 1, 1), neg_urg_1 = c(2,
2, 2), neg_urg_2 = c(2, 2, 2), neg_urg_3 = c(2, 2, 2), neg_urg_4 = c(2,
2, 2), neg_urg_5 = c(3, 3, 3), neg_urg_6 = c(2, 2, 2), neg_urg_7 = c(2,
2, 2), neg_urg_8 = c(3, 3, 3), neg_urg_9 = c(2, 2, 2), neg_urg_10 = c(2,
2, 2), neg_urg_11 = c(3, 3, 3), neg_urg_12 = c(2, 2, 2),
dis_tol_1 = c(3, 3, 3), dis_tol_2 = c(3, 3, 3), dis_tol_3 = c(2,
2, 2), dis_tol_4 = c(3, 3, 3), dis_tol_5 = c(4, 4, 4), dis_tol_6 = c(4,
4, 4), dis_tol_7 = c(3, 3, 3), dis_tol_8 = c(4, 4, 4), dis_tol_9 = c(3,
3, 3), dis_tol_10 = c(2, 2, 2), dis_tol_11 = c(2, 2, 2),
dis_tol_12 = c(3, 3, 3), dis_tol_13 = c(4, 4, 4), dis_tol_14 = c(4,
4, 4), dis_tol_15 = c(3, 3, 3), lone_1 = c(3, 3, 3), lone_2 = c(2,
2, 2), lone_3 = c(3, 3, 3), lone_4 = c(3, 3, 3), lone_5 = c(2,
2, 2), lone_6 = c(3, 3, 3), lone_7 = c(2, 2, 2), lone_8 = c(3,
3, 3), lone_9 = c(3, 3, 3), lone_10 = c(2, 2, 2), lone_11 = c(3,
3, 3), lone_12 = c(2, 2, 2), lone_13 = c(3, 3, 3), lone_14 = c(3,
3, 3), lone_15 = c(2, 2, 2), lone_16 = c(3, 3, 3), lone_17 = c(2,
2, 2), lone_18 = c(3, 3, 3), lone_19 = c(3, 3, 3), lone_20 = c(3,
3, 3), ucla_1 = c(3, 3, 3), ucla_2 = c(3, 3, 3), ucla_3 = c(3,
3, 3), appear_1a = c(5, 5, 5), appear_1e = c(4, 4, 4), appear_2a = c(5,
5, 5), appear_2e = c(5, 5, 5), appear_3a = c(4, 4, 4), appear_3e = c(4,
4, 4), appear_4a = c(5, 5, 5), appear_4e = c(5, 5, 5), appear_5a = c(5,
5, 5), appear_5e = c(4, 4, 4), appear_6a = c(5, 5, 5), appear_6e = c(4,
4, 4), appear_7a = c(4, 4, 4), appear_7e = c(5, 5, 5), appear_8a = c(5,
5, 5), appear_8e = c(5, 5, 5), appear_9a = c(5, 5, 5), appear_9e = c(4,
4, 4), appear_10a = c(5, 5, 5), appear_10e = c(5, 5, 5),
object_1 = c(3, 3, 3), object_2 = c(1, 1, 1), object_3 = c(2,
2, 2), object_4 = c(4, 4, 4), object_5 = c(12, 12, 12), object_6 = c(5,
5, 5), object_7 = c(11, 11, 11), object_8 = c(6, 6, 6), object_9 = c(10,
10, 10), object_10 = c(7, 7, 7), object_11 = c(8, 8, 8),
object_12 = c(9, 9, 9), rrs_1 = c(NA_real_, NA_real_, NA_real_
), rrs_2 = c(NA_real_, NA_real_, NA_real_), rrs_3 = c(NA_real_,
NA_real_, NA_real_), rrs_4 = c(NA_real_, NA_real_, NA_real_
), rrs_5 = c(NA_real_, NA_real_, NA_real_), rrs_6 = c(NA_real_,
NA_real_, NA_real_), rrs_7 = c(NA_real_, NA_real_, NA_real_
), rrs_8 = c(NA_real_, NA_real_, NA_real_), rrs_9 = c(NA_real_,
NA_real_, NA_real_), rrs_10 = c(NA_real_, NA_real_, NA_real_
), negative_urgency_tot = c(34, 34, 34), smartphone = c(NA_real_,
NA_real_, NA_real_), eat_26_total = c(48, 48, 48), eat26_oral_control = c(5,
5, 5), eat26_bulimia_food = c(11, 11, 11), eat26_diet = c(32,
32, 32), total_lone = c(49, 49, 49), total_object = c(78,
78, 78), rrs_total = c(NA_real_, NA_real_, NA_real_), total_dis_tol = c(45,
45, 45), total_body_sat = c(46, 46, 46), totalsocio = c(35,
35, 35), total_bodyimage = c(50, 50, 50), total_media = c(12,
12, 12), total_critical = c(19, 19, 19), total_intro_aware = c(7,
7, 7), intro_aware1_recoded = c(1, 1, 1), totalcesdrecoded = c(13,
13, 13), itro_aware_2recoded = c(2, 2, 2), intro_aware_3recoded = c(2,
2, 2), intro_aware4_recoded = c(2, 2, 2), cesd_1recoded = c(1,
1, 1), cesd_2recoded = c(1, 1, 1), cesd_3recoded = c(2, 2,
2), cesd_4recoded = c(2, 2, 2), cesd_5reversecoded = c(1,
1, 1), cesd_6recoded = c(1, 1, 1), cesd_7recoded = c(1, 1,
1), cesd_8reversecoded = c(1, 1, 1), cesd_9recoded = c(2,
2, 2), cesd_10recoded = c(1, 1, 1), recoded_eat26_q1 = c(3,
3, 3), recoded_eat26_q2 = c(0, 0, 0), recoded_eat26_q3 = c(3,
3, 3), recoded_eat26_q4 = c(3, 3, 3), recoded_eat26_q5 = c(3,
3, 3), recoded_eat26_q6 = c(3, 3, 3), recoded_eat26_q7 = c(3,
3, 3), recoded_eat26_q8 = c(0, 0, 0), recoded_eat26_q9 = c(0,
0, 0), recoded_eat26_q10 = c(2, 2, 2), recoded_eat26_q11 = c(3,
3, 3), recoded_eat26_q12 = c(3, 3, 3), recoded_eat26_q13 = c(0,
0, 0), recoded_eat26_q14 = c(2, 2, 2), recoded_eat26_q15 = c(0,
0, 0), recoded_eat26_q16 = c(1, 1, 1), recoded_eat26_q17 = c(2,
2, 2), recoded_eat26_q18 = c(2, 2, 2), recoded_eat26_q19 = c(2,
2, 2), recoded_eat26_q20 = c(0, 0, 0), recoded_eat26_q21 = c(3,
3, 3), recoded_eat26_q22 = c(3, 3, 3), recoded_eat26_q23 = c(2,
2, 2), recoded_eat26_q24 = c(2, 2, 2), recoded_eat26_q25 = c(3,
3, 3), recoded_eat26_q26 = c(0, 0, 0), dis_tol_6recoded = c(2,
2, 2), lone_1recoded = c(2, 2, 2), lone_5recoded = c(3, 3,
3), lone_6recoded = c(2, 2, 2), lone_9recoded = c(2, 2, 2
), lone_10recoded = c(3, 3, 3), lone_15recoded = c(3, 3,
3), lone_16recoded = c(2, 2, 2), lone_19recoded = c(2, 2,
2), lone_20recoded = c(2, 2, 2), lone_4recoded = c(2, 2,
2), neg_urg_1recoded = c(3, 3, 3), neg_urg_2recoded = c(3,
3, 3), neg_urg_3recoded = c(3, 3, 3), neg_urg_4recoded = c(3,
3, 3), neg_urg_5recoded = c(2, 2, 2), neg_urg_6recoded = c(3,
3, 3), neg_urg_7recoded = c(3, 3, 3), neg_urg_8recoded = c(2,
2, 2), neg_urg_9recoded = c(3, 3, 3), neg_urg_10recoded = c(3,
3, 3), neg_urg_12recoded = c(3, 3, 3), filter = c(1, 1, 1
), EatingSum = c(NA, 0, 1), EatingMean = c(NA, 0, 0.166666666666667
), appearsum = c(216, 216, 216), appearT = c(21.6, 21.6,
21.6), sexualorientation_col = c(NA_real_, NA_real_, NA_real_
), sat1r = c(NA, 6, 8), happyr = c(NA, 5, 5), dating1r = c(NA,
2, 1), datingappr = c(2, 2, 2), currentheight_metre = c(1.58,
1.58, 1.58), BMI = c(22.0317256849864, 22.0317256849864,
22.0317256849864), employed_sum = c(0, 0, 0), employed = c(0,
0, 0), unemployed = c(0, 0, 0), IDorder = 1:3, Date = structure(c(NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = ""),
FirstDate = structure(c(NA_real_, NA_real_, NA_real_), class = c("POSIXct",
"POSIXt"), tzone = ""), DaysElapsed = structure(c(NA_real_,
NA_real_, NA_real_), class = "difftime", units = "secs")), row.names = c(NA,
-3L), groups = structure(list(participant_id = 5237430, .rows = structure(list(
1:3), ptype = integer(0), class = c("vctrs_list_of", "vctrs_vctr",
"list"))), row.names = 1L, class = c("tbl_df", "tbl", "data.frame"
), .drop = TRUE), class = c("grouped_df", "tbl_df", "tbl", "data.frame"
))

densityplot error occurs when trying to run densityplot post mice with two variables removed

I am trying to run kernel density estimates of the imputed and observed data. However, I don't want to include variables "FOC_2", and "FOC_3" - they are hierarchical and mess up the imputations. The code runs with the full data set. However when I remove the aforementioned variables I get - 'Error in density.default(x = c(NA_real_, NA_real_, NA_real_, NA_real_,:need at least 2 points to select a bandwidth automatically'
Here is a subset of the data:
> dput(diss_data[1:4,])
structure(list(DS_1 = c(5, 10, 1, 10), DS_2 = c(10, 10, 1, NA
), DS_3 = c(5, 10, NA, 10), DS_4 = c(10, 10, 1, 10), DS_5 = c(10,
8, 2, 9), DS_6 = c(10, 9, 10, 10), DS_7 = c(5, 6, 5, 10), ISR_1 = c(3,
7, 1, NA), ISR_2 = c(10, 5, 2, NA), ISR_3 = c(7, 8, 1, NA), ISR_4 = c(10,
8, 1, NA), ISR_5 = c(10, 10, NA, NA), SC_T1 = c(1, 1, 2, 10),
SC_T2 = c(1, 1, 1, 10), SC_T3 = c(5, 1, 2, 10), SC_T4 = c(5,
8, NA, 10), SC_T5 = c(5, 7, 10, 10), FOC_1 = structure(c(2L,
2L, 1L, 2L), .Label = c("1", "2"), class = "factor"), FOC_2 = c(1,
1, 1, NA), FOC_3 = c(NA, 1, NA, 10), PS_1 = c(NA, 5, 1, 10
), PR_1 = c(1, 1, NA, NA), PR_2 = c(5, 1, NA, 1), PR_3 = c(1,
1, 1, 1), PR_4 = c(5, 10, NA, 1), PR_5 = c(1, 1, 10, NA),
PR_6 = c(5, 1, 5, 1), PR_7 = c(5, 1, 10, NA), PR_8 = c(5,
1, 10, NA), DR_1 = structure(c(2L, 2L, 1L, 2L), .Label = c("1",
"2"), class = "factor"), IR_1 = structure(c(2L, 2L, 1L, 2L
), .Label = c("1", "2"), class = "factor"), PF_1 = c(5, 1,
10, 10), PF_2 = c(5, 1, 10, 10), PF_3 = c(1, 1, 9, 10), PF_4 = c(10,
7, 2, 10), PF_5 = c(10, 10, 6, 10), DF_1 = c(5, 10, 1, NA
), DF__2 = c(5, 8, 10, 10), L_1 = c(5, 5, 8, 10), L_2 = c(5,
6, 10, 10), PE_1 = c(NA, 10, 5, 10), PE_2 = c(NA, 8, 10,
10), PE_3 = c(NA, 9, 10, 10), PE_4 = c(NA, 10, 10, 10), PE_5 = c(10,
8, 9, 10), PE_6 = c(10, 10, 10, 10), PE_7 = c(1, 10, 10,
10), YRS_N = c(15, 20, 10, NA), AGE = c(22, 60, 53, 24),
GENDER = c(2, 1, 1, NA), M_S = c(2, 1, 1, NA), RACE = c(5,
2, 2, 5), HAITI = structure(c(1L, 1L, 1L, 1L), .Label = c("1",
"2"), class = "factor"), H_INC = c(1, 1, 3, 1), H_O = c(2,
2, 1, NA), TREATMENT = structure(c(1L, 1L, 1L, 1L), .Label = c("0",
"1"), class = "factor")), row.names = c(NA, 4L), class = "data.frame")
Here is my code:
library(mice)
init = mice(diss_data, maxit=0)
meth = init$method
predM = init$predictorMatrix
meth[c("FOC_2", "FOC_3")]=""
imp <-mice(diss_data, method = meth, maxit = 10, m = 10)
densityplot(imp, layout = c(3, 6))
Error in density.default(x = c(NA_real_, NA_real_, NA_real_,
NA_real_,:need at least 2 points to select a bandwidth automatically
I read this "The relevant error message is: Error in density.default: ... need at least 2 points to select a bandwidth automatically. There is yet no workaround for this problem. Use the more robust bwplot or stripplot as a replacement" via https://rdrr.io/cran/mice/man/densityplot.mids.html.
Is it safe to say I cannot use densityplot and should use bwplot or stripplot? Or is there actually a workaround? Please bear with me I am new to R and thank you in advance for any assistance.

recoding variables in a loop in R

I want to recode several variables together. All these variables will undergo same recoding change.
For this, I followed the thread below. The thread below describes two ways of doing it.
1). Using column number
2). using variable names
I tried both but I get an error message.
Error message for 1) and 2).
Error in (function (var, recodes, as.factor, as.numeric = TRUE, levels) :
unused arguments (2 = "1", 3 = "1", 1 = "0", 4 = "0", na.rm = TRUE)
recode variable in loop R
#Uploading libraries
library(dplyr)
library(magrittr)
library(plyr)
library(readxl)
library(tidyverse)
#Importing file
mydata <- read_excel("CCorr_Data.xlsx")
df <- data.frame(mydata)
attach(df)
#replacing codes for variables
df %>%
mutate_at(c(1:7), recode, '2'='1', '3'='1', '1'='0', '4'='0', na.rm = TRUE) %>%
mutate_at(c(15:24), recode, '2'='0', na.rm = TRUE)
df %>%
mutate_at(vars(E301, E302, E303), recode,'2'='1', '3'='1', '1'='0', '4'='0', na.rm = TRUE) %>%
mutate_at(vars(B201, B202, B203), recode, '2'='0', na.rm = TRUE)
Can someone tell me where am I going wrong?
In my dataset there are missing values that's why I have included na.rm = T. I even tried without including the missing value command, the error message was the same even then.
Please see below for sample data.
structure(list(Country = c(1, 1, 1, 1, 1, 1), HHID = c("12ae5148e245079f-122042",
"12ae5148e245079f-123032", "12ae5148e245079f-123027", "12ae5148e245079f-123028",
"12ae5148e245079f-N123001", "12ae5148e245079f-123041"), HHCode = c("122042",
"123032", "123027", "123028", "N123001", "123041"), A103 = c(2,
2, 2, 2, 2, 2), A104 = c("22", "23", "23", "23", "23", "23"),
Community = c("Mehmada", "Dhobgama", "Dhobgama", "Dhobgama",
"Dhobgama", "Dhobgama"), E301 = c(3, 3, 3, 3, 3, 3), E302 = c(3,
2, 4, 4, 3, 3), E303 = c(3, 2, 3, 3, 3, 3), E304 = c(3, 4,
4, 4, 3, 3), E305 = c(3, 2, 3, 3, 3, 3), E306 = c(3, 3, 3,
3, 3, 3), E307 = c(3, 3, 3, 3, 3, 3), E308 = c(3, 1, 3, 3,
3, 3), B201.1 = c(NA, 1, 1, 1, 1, 1), B202.1 = c(NA, 1, 1,
1, 1, 1), B203.1 = c(NA, 1, 1, 2, 2, 1), B204.1 = c(NA, 2,
1, 2, 1, 1), B205.1 = c(NA, 2, 1, 2, 2, 2), B206.1 = c(NA,
1, 1, 1, 2, 1), B207.1 = c(NA, 2, 1, 2, 2, 1), B208.1 = c(NA,
2, 2, 2, 2, 2), B209.1 = c(NA, 2, 1, 1, 1, 1), B210.1 = c(NA,
1, 1, 1, 1, 1)), row.names = c(NA, 6L), class = "data.frame")
```
The issue is with in the na.rm = TRUE, recode doesn't have that argument
library(dplyr)
df %>%
mutate_at(vars(E301, E302, E303), recode,'2'='1', '3'='1', '1'='0', '4'='0') %>%
mutate_at(vars(B201, B202, B203), recode, '2'='0')
Try using :
library(dplyr)
df %>%
mutate_at(1:7, recode, '2'='1', '3'='1', '1'='0', '4'='0') %>%
mutate_at(15:24, recode, '2'='0')

"sample sizes in the longitudinal and event processes differ" in JointModel in r

I am trying to perform a joint model analysis with simulated data. I believe I have formatted the data properly, but I receive this error:
"Error in jointModel(lmeFitJ, coxFit, timeVar = "time.point") :
sample sizes in the longitudinal and event processes differ; maybe you forgot the cluster() argument."
I only see this mentioned in the source code for JM and in one brief and unresolved troubleshooting thread. Where have I messed up? Thank you for any help!
Minimal complete example with first 4 participants:
#required packages
library(readxl, nlme, JM)
#long_data
structure(list(particip.id = c(1, 1, 1, 1, 2, 2, 3, 4, 4, 4,
4), time.point = c(1, 2, 3, 4, 1, 2, 1, 1, 2, 3, 4), school4me = c("DPU",
"DPU", "DPU", "DPU", "DPU", "DPU", "DPU", "DPU", "DPU", "DPU",
"DPU"), hours.a = c(3, 3, 2, 3, 0, 0, 6, 10, 13, 16, 15), hours.b = c(4,
6, 0, 0, 0, 1, 3, 7, 15, 9, 10), enrolled = c(1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1), TimeQ = c(4, 4, 4, 4, 2.9369807105977, 2.9369807105977,
1.50240888306871, 4, 4, 4, 4)), row.names = c(NA, -11L), class = c("tbl_df",
"tbl", "data.frame"))
#short_data
structure(list(particip.id = c(1, 2, 3, 4), time.point = c(3,
2, 3, 4), school4me = c("DPU", "DPU", "DPU", "DPU"), enrolled = c(0,
0, 0, 1), TimeQ = c(2.376576055, 1.152660467, 2.300307851, 4),
actual = c(1, 1, 1, 0)), row.names = c(NA, -4L), class = c("tbl_df",
"tbl", "data.frame"))
#Analysis
lmeFitJ <- lme(hours.a ~ time.point + time.point:school4me, data=long_data, random = ~time.point | particip.id)
coxFit <- coxph(Surv(TimeQ, actual) ~ school4me, data = short_data, x = TRUE)
fitJOINT <- jointModel(lmeFitJ, coxFit, timeVar = "time.point")
#analysis produces: "Error in jointModel(lmeFitJ, coxFit, timeVar = "time.point") : sample sizes in
#the longitudinal and event processes differ; maybe you forgot the cluster() argument."
In the source code you can find
if (is.null(survObject$model))
stop("\nplease refit the Cox model including in the ",
"call to coxph() the argument 'model = TRUE'.")
and
nT <- length(unique(idT))
if (LongFormat && is.null(survObject$model$cluster))
stop("\nuse argument 'model = TRUE' and cluster() in coxph().")
Unfortunately the longitudinal process warning is occurring first so you don't see them.
("sample sizes in the longitudinal and event processes differ; ",
"maybe you forgot the cluster() argument.\n")
Try adding model = TRUE and cluster(particip.id) to your coxFit i.e.
coxFit <- coxph(Surv(TimeQ, actual) ~ school4me + cluster(particip.id), data = short_data, x = TRUE, model = TRUE)

Preparing data before doing Principal component analysis (PCA)

I have a data frame(200x300) which consists of mixed(character,numeric) variables and has lots of missing values(NA)
my first problem is how to convert all data into numeric, I can use factors but there are like 100 columns to convert.
secondly, all my columns are not expressed in equivalent units.
I just want some good advice for preparing the data before starting with my analysis
following is the structure of the data
structure(list(Hormonal.cycle.status..P4. = c(1, 1, 4, 1, 4,
1), Hormonal.medication.status = c(2, 1, 1, 2, 1, 1), Hormonal.medication.type = c(21,
27, 27, 26, 27, 27), ID.pathologist.main = c(3, 3, 3, 4, 2, 1
), ID.pathologist.sub = c(2, 1, 2, 2, 2, 2), Day.of.the.cycle_calculated = c(10,
8, 22, 19, 19, 12), Cycle.status..histology.and.cycle.day. = c(12,
18, 9, 1, 18, 3), Cycle.status.final..P4..histology..cycle.day. = c(1,
4, 5, 1, 6, 3), Deep.lesion = c(2, 2, 1, 2, 1, 2), Ovarian.lesion = c(2,
2, 2, 1, 2, 2), Peritoneal.lesion = c(2, 2, 2, 2, 2, 2), Combination.of.lesions = c(1,
1, 7, 4, 7, 1), DEEP.all.types = c(2, 2, NA, 2, NA, 2), DEEP.uterosacral = c(2,
2, NA, 2, NA, 2), DEEP.RVE = c(1, 1, 1, 2, 1, 1), DEEP.bowel = c(1,
1, 1, 1, 1, 1), DEEP.bladder = c(1, 1, 1, 1, 1, 1), Ovarian.endo.cyst = c(5,
5, 3, 1, 3, 5), Peritoneal = c(2, NA, 2, NA, 2, 2), Peritoneal.size.total = c(3,
3, 3, 3, 3, 2), Date.of.the.surgery = c(96, 98, 17, 105, 107,
108), Type.of.surgery = c(1, 1, 1, 1, 1, 1), Perit..surface = c(1,
2, 3, 3, 2, 2), Perit..deep = c(3, NA, NA, NA, 3, 3), R.ovary.surface = c(NA,
1, 2, 1, 1, NA), R.ovary.deep = c(NA, NA, 2, NA, 3, NA), L.ovary.surface = c(2,
NA, 2, NA, 1, NA), L.ovary.deep = c(2, 4, 4, NA, 4, 4), F.d.block = c(NA,
NA, 1, 1, NA, 1), R.ovary.frail = c(NA, NA, 3, NA, NA, 3), R.ovary.tight = c(NA,
NA, NA, NA, 3, NA), L.ovary.frail = c(NA, NA, NA, 2, NA, NA),
L.ovary.tight = c(2, 2, 3, NA, 2, 2), R.tuba.frail = c(NA,
NA, NA, NA, NA, 2), R.tuba.tight = c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_), L.tuba.frail = c(NA,
NA, NA, NA, NA, 2), L.tuba.tight = c(4, NA, NA, NA, 4, NA
), Elsewhere = c(35, NA, NA, 24, NA, NA), Other.diseases = c(16,
NA, NA, NA, NA, 11), In.microarray = c(2, 2, 1, 2, 2, 1),
In.cytokine.plexes = c(2, 2, 2, 2, 2, 2)), .Names = c("Hormonal.cycle.status..P4.",
"Hormonal.medication.status", "Hormonal.medication.type", "ID.pathologist.main",
"ID.pathologist.sub", "Day.of.the.cycle_calculated", "Cycle.status..histology.and.cycle.day.",
"Cycle.status.final..P4..histology..cycle.day.", "Deep.lesion",
"Ovarian.lesion", "Peritoneal.lesion", "Combination.of.lesions",
"DEEP.all.types", "DEEP.uterosacral", "DEEP.RVE", "DEEP.bowel",
"DEEP.bladder", "Ovarian.endo.cyst", "Peritoneal", "Peritoneal.size.total",
"Date.of.the.surgery", "Type.of.surgery", "Perit..surface", "Perit..deep",
"R.ovary.surface", "R.ovary.deep", "L.ovary.surface", "L.ovary.deep",
"F.d.block", "R.ovary.frail", "R.ovary.tight", "L.ovary.frail",
"L.ovary.tight", "R.tuba.frail", "R.tuba.tight", "L.tuba.frail",
"L.tuba.tight", "Elsewhere", "Other.diseases", "In.microarray",
"In.cytokine.plexes"), row.names = c("H003", "H004", "H006",
"H007", "H008", "H011"), class = "data.frame")

Resources