strange error when creating a model with zelig - r

dput(t)
structure(list(Volume = c(2625941L, 4685483L, 3160694L, 2627816L,
2430273L, 2498011L, 2632445L, 3224434L, 2531941L, 5043867L, 2788003L,
3278796L, 3273977L, 3192613L, 3456297L, 2668175L, 2805861L, 2689392L,
2733510L, 3285889L, 2957370L, 3420479L, 3868692L, 4353776L, 3134759L,
2914727L, 3160491L, 3803716L, 3427911L, 2646258L, 3616962L, 3071943L,
3013008L, 4024996L, 4357129L, 3110560L, 3063334L, 4537971L, 1902002L,
2618413L, 2473005L, 2844029L, 2398462L, 3406776L, 3071573L, 3714231L,
4276458L, 3825187L, 2652650L, 3040994L, 2695117L, 3038566L, 2695652L,
2919113L, 2840214L, 2768958L, 5246649L, 3023172L, 3565584L, 2928450L,
3503840L, 2948165L, 3512192L, 3409995L, 3511665L, 3155152L, 3020401L,
2758133L, 2548245L, 3033309L, 2740213L, 2851881L, 3134557L, 4445879L,
3173913L, 3720477L, 3753070L, 3609973L, 3826284L, 4864280L, 4159588L,
3095322L, 3138732L, 3591433L, 3063357L, 3215559L, 3258059L, 3559727L,
4886550L, 4025763L, 4108614L, 5720774L, 4075195L, 3322352L, 3048940L,
3249172L, 3148053L, 3321660L, 3159642L, 3976820L, 3848960L, 3466783L,
3811408L, 6033563L, 4114751L, 3181385L, 2926695L, 2866148L, 2692198L,
3400891L, 2922295L, 3912049L, 3079066L, 2833293L, 3560196L, 3317644L,
3151086L, 3776538L, 5479510L, 3954497L, 3594429L, 3088262L, 2778180L,
3532457L), SLA = c(28L, 44L, 12L, 28L, 4L, 28L, 4L, 4L, 8L, 12L,
8L, 4L, 8L, 4L, 8L, 8L, 32L, 4L, 36L, 8L, 4L, 8L, 20L, 8L, 32L,
12L, 32L, 8L, 16L, 40L, 8L, 20L, 4L, 4L, 8L, 20L, 16L, 4L, 12L,
8L, 4L, 8L, 4L, 4L, 8L, 12L, 12L, 16L, 28L, 28L, 12L, 16L, 16L,
8L, 20L, 20L, 24L, 44L, 12L, 24L, 24L, 24L, 20L, 24L, 36L, 16L,
40L, 24L, 4L, 44L, 8L, 16L, 12L, 8L, 32L, 12L, 20L, 16L, 28L,
8L, 24L, 24L, 4L, 4L, 8L, 8L, 4L, 12L, 8L, 44L, 12L, 24L, 40L,
8L, 4L, 8L, 12L, 12L, 8L, 16L, 24L, 8L, 36L, 48L, 36L, 12L, 36L,
28L, 20L, 12L, 20L, 32L, 24L, 4L, 12L, 16L, 8L, 24L, 16L, 36L,
44L, 12L, 8L, 4L), Duration = c(21L, 25L, 15L, 13L, 15L, 20L,
17L, 20L, 12L, 15L, 31L, 12L, 24L, 16L, 25L, 13L, 13L, 20L, 21L,
20L, 26L, 15L, 26L, 21L, 27L, 20L, 34L, 29L, 74L, 62L, 33L, 27L,
26L, 23L, 30L, 26L, 26L, 18L, 19L, 13L, 25L, 18L, 20L, 18L, 37L,
20L, 22L, 25L, 24L, 22L, 42L, 17L, 18L, 18L, 28L, 18L, 28L, 32L,
23L, 31L, 12L, 30L, 40L, 30L, 18L, 18L, 19L, 27L, 21L, 31L, 23L,
26L, 14L, 22L, 21L, 21L, 26L, 30L, 21L, 23L, 12L, 22L, 24L, 29L,
36L, 19L, 21L, 25L, 24L, 29L, 26L, 34L, 33L, 17L, 17L, 24L, 19L,
18L, 12L, 18L, 11L, 19L, 22L, 48L, 49L, 25L, 16L, 43L, 18L, 18L,
19L, 15L, 38L, 19L, 22L, 28L, 28L, 34L, 16L, 53L, 38L, 23L, 27L,
17L)), .Names = c("Volume", "SLA", "Duration"), class = "data.frame", row.names = c(2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L,
17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L,
30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L,
43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L,
56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L,
69L, 70L, 71L, 72L, 73L, 75L, 76L, 77L, 79L, 80L, 81L, 82L, 84L,
85L, 86L, 87L, 88L, 89L, 90L, 91L, 92L, 93L, 94L, 95L, 96L, 97L,
98L, 99L, 100L, 101L, 102L, 103L, 105L, 106L, 107L, 108L, 110L,
111L, 112L, 113L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L,
123L, 124L, 125L, 126L, 127L, 128L, 129L, 130L, 131L))
when I do this:
z.out1 <- zelig(Duration ~ Volume, model = "logit", data = t)
I get this error:
Error in `rownames<-`(`*tmp*`, value = c(1L, 0L)) :
attempt to set rownames on object with no dimensions
any ideas?

Related

Convert quarter character into date object in R

I have a dataset and a column in there with information on the "period" of the observations which is a character for quarters of year. The column looks like this:
> dput(df$Period)
structure(c(27L, 40L, 1L, 3L, 15L, 42L, 29L, 35L, 21L, 48L, 9L,
41L, 28L, 2L, 14L, 45L, 32L, 18L, 6L, 22L, 49L, 36L, 10L, 27L,
1L, 40L, 2L, 41L, 14L, 28L, 15L, 3L, 42L, 29L, 6L, 32L, 45L,
18L, 48L, 21L, 35L, 9L, 10L, 49L, 22L, 36L, 2L, 41L, 28L, 14L,
45L, 6L, 18L, 32L, 10L, 49L, 22L, 36L, 18L, 6L, 45L, 32L, 49L,
36L, 22L, 10L, 14L, 2L, 41L, 28L, 45L, 18L, 32L, 6L, 49L, 10L,
22L, 36L, 32L, 18L, 45L, 6L, 36L, 10L, 22L, 49L, 14L, 41L, 28L,
2L, 27L, 40L, 1L, 35L, 9L, 48L, 21L, 27L, 40L, 1L, 35L, 21L,
48L, 9L, 1L, 40L, 27L, 41L, 28L, 2L, 14L, 42L, 15L, 3L, 29L,
32L, 45L, 6L, 18L, 48L, 9L, 21L, 35L, 10L, 49L, 36L, 22L, 1L,
40L, 27L, 14L, 28L, 41L, 2L, 29L, 15L, 42L, 3L, 18L, 6L, 32L,
45L, 49L, 36L, 22L, 10L, 27L, 1L, 40L, 2L, 41L, 28L, 14L, 15L,
42L, 29L, 3L, 6L, 45L, 18L, 32L, 7L, 19L, 46L, 33L, 9L, 35L,
21L, 48L, 10L, 22L, 49L, 36L, 1L, 40L, 27L, 2L, 14L, 28L, 41L,
3L, 42L, 15L, 29L, 18L, 32L, 45L, 6L, 46L, 33L, 19L, 7L, 35L,
9L, 21L, 48L, 49L, 22L, 36L, 10L, 1L, 27L, 40L, 29L, 15L, 3L,
42L, 45L, 6L, 18L, 32L, 9L, 21L, 35L, 48L, 36L, 49L, 10L, 22L,
2L, 28L, 14L, 41L, 32L, 18L, 45L, 6L, 36L, 49L, 22L, 10L, 1L,
27L, 40L, 43L, 30L, 16L, 4L, 44L, 31L, 17L, 5L, 32L, 18L, 45L,
6L, 49L, 36L, 22L, 10L, 27L, 40L, 1L, 9L, 35L, 21L, 48L, 27L,
1L, 40L, 2L, 41L, 28L, 14L, 42L, 29L, 15L, 3L, 18L, 6L, 32L,
45L, 46L, 7L, 19L, 33L, 48L, 21L, 9L, 35L, 36L, 10L, 22L, 49L,
14L, 28L, 41L, 2L, 32L, 6L, 18L, 45L, 22L, 10L, 49L, 36L, 40L,
1L, 27L, 14L, 41L, 28L, 2L, 42L, 29L, 15L, 3L, 6L, 18L, 45L,
32L, 33L, 19L, 7L, 46L, 9L, 48L, 35L, 21L, 36L, 49L, 10L, 22L,
41L, 28L, 2L, 14L, 18L, 6L, 45L, 32L, 36L, 22L, 49L, 10L, 41L,
2L, 28L, 14L, 45L, 18L, 6L, 32L, 22L, 36L, 49L, 10L, 40L, 27L,
1L, 28L, 41L, 2L, 14L, 3L, 15L, 29L, 42L, 32L, 18L, 6L, 45L,
35L, 21L, 48L, 9L, 36L, 22L, 10L, 49L, 32L, 45L, 6L, 18L, 10L,
22L, 49L, 36L, 41L, 28L, 14L, 2L, 45L, 18L, 6L, 32L, 36L, 49L,
10L, 22L, 28L, 2L, 41L, 14L, 45L, 6L, 32L, 18L, 22L, 36L, 10L,
49L, 27L, 1L, 40L, 14L, 2L, 28L, 41L, 42L, 3L, 29L, 15L, 17L,
44L, 31L, 5L, 6L, 32L, 18L, 45L, 9L, 48L, 35L, 21L, 36L, 22L,
10L, 49L, 2L, 14L, 41L, 28L, 32L, 18L, 45L, 6L, 49L, 22L, 10L,
36L, 41L, 28L, 14L, 2L, 6L, 45L, 32L, 18L, 22L, 10L, 49L, 36L,
40L, 1L, 27L, 35L, 21L, 9L, 48L, 1L, 40L, 27L, 14L, 2L, 28L,
41L, 29L, 3L, 15L, 42L, 6L, 45L, 32L, 18L, 46L, 7L, 33L, 19L,
21L, 9L, 35L, 48L, 36L, 10L, 22L, 49L, 28L, 41L, 2L, 14L, 18L,
6L, 45L, 32L, 36L, 22L, 49L, 10L, 1L, 40L, 27L, 28L, 14L, 41L,
2L, 16L, 30L, 43L, 4L, 45L, 6L, 32L, 18L, 20L, 8L, 47L, 34L,
9L, 35L, 48L, 21L, 22L, 36L, 49L, 10L, 41L, 2L, 28L, 14L, 18L,
32L, 45L, 6L, 49L, 22L, 10L, 36L, 27L, 1L, 40L, 48L, 35L, 9L,
21L, 14L, 2L, 41L, 28L, 6L, 45L, 18L, 32L, 36L, 49L, 10L, 22L,
40L, 1L, 27L, 41L, 2L, 28L, 14L, 42L, 3L, 15L, 29L, 17L, 31L,
44L, 5L, 32L, 18L, 45L, 6L, 46L, 33L, 19L, 7L, 9L, 35L, 21L,
48L, 36L, 49L, 10L, 22L, 6L, 18L, 32L, 45L, 10L, 49L, 22L, 36L,
1L, 27L, 40L, 2L, 41L, 28L, 14L, 42L, 29L, 15L, 3L, 18L, 32L,
45L, 6L, 46L, 7L, 33L, 19L, 48L, 21L, 9L, 35L, 49L, 10L, 22L,
36L, 27L, 1L, 40L, 2L, 28L, 14L, 41L, 15L, 3L, 42L, 29L, 45L,
32L, 6L, 18L, 9L, 35L, 48L, 21L, 10L, 36L, 49L, 22L, 40L, 1L,
27L, 41L, 28L, 14L, 2L, 42L, 15L, 29L, 3L, 32L, 6L, 45L, 18L,
46L, 19L, 33L, 7L, 35L, 9L, 21L, 48L, 10L, 22L, 36L, 49L, 27L,
1L, 40L, 41L, 14L, 2L, 28L, 29L, 3L, 15L, 42L, 44L, 31L, 17L,
5L, 6L, 18L, 32L, 45L, 7L, 46L, 33L, 19L, 21L, 35L, 9L, 48L,
22L, 49L, 36L, 10L, 1L, 40L, 27L, 35L, 48L, 9L, 21L, 27L, 1L,
40L, 2L, 28L, 41L, 14L, 42L, 29L, 3L, 15L, 18L, 6L, 32L, 45L,
7L, 33L, 46L, 19L, 9L, 21L, 35L, 48L, 36L, 22L, 10L, 49L, 41L,
2L, 14L, 28L, 18L, 6L, 45L, 32L, 10L, 22L, 49L, 36L, 1L, 40L,
27L, 28L, 14L, 41L, 2L, 42L, 29L, 3L, 15L, 18L, 32L, 45L, 6L,
7L, 33L, 19L, 46L, 35L, 48L, 9L, 21L, 49L, 36L, 22L, 10L, 40L,
1L, 27L, 41L, 2L, 14L, 28L, 15L, 3L, 29L, 42L, 45L, 32L, 6L,
18L, 19L, 7L, 33L, 46L, 21L, 48L, 9L, 35L, 36L, 22L, 49L, 10L,
4L, 30L, 43L, 18L, 45L, 32L, 6L, 10L, 36L, 49L, 22L, 28L, 2L,
41L, 14L, 45L, 32L, 6L, 18L, 22L, 36L, 49L, 10L, 41L, 28L, 2L,
14L, 45L, 6L, 32L, 18L, 22L, 36L, 49L, 10L, 27L, 1L, 40L, 3L,
15L, 29L, 42L, 46L, 7L, 33L, 19L, 9L, 35L, 21L, 48L, 27L, 40L,
1L, 2L, 14L, 41L, 28L, 15L, 3L, 42L, 29L, 32L, 6L, 18L, 45L,
7L, 19L, 33L, 46L, 35L, 9L, 21L, 48L, 36L, 49L, 22L, 10L, 6L,
45L, 18L, 32L, 22L, 36L, 49L, 10L, 45L, 32L, 18L, 6L, 10L, 22L,
49L, 36L, 27L, 40L, 1L, 41L, 28L, 2L, 14L, 45L, 6L, 18L, 32L,
36L, 49L, 10L, 22L, 14L, 41L, 28L, 2L, 18L, 32L, 45L, 6L, 49L,
10L, 22L, 36L, 6L, 45L, 32L, 18L, 22L, 27L, 1L, 40L, 2L, 41L,
28L, 14L, 3L, 42L, 15L, 29L, 45L, 6L, 32L, 18L, 46L, 7L, 19L,
33L, 48L, 35L, 21L, 9L, 49L, 10L, 22L, 36L, 31L, 17L, 44L, 5L,
18L, 40L, 1L, 27L, 2L, 14L, 41L, 28L, 42L, 3L, 29L, 15L, 18L,
6L, 45L, 32L, 19L, 7L, 46L, 33L, 21L, 35L, 48L, 9L, 22L, 10L,
49L, 36L, 1L, 27L, 40L, 41L, 2L, 28L, 14L, 6L, 32L, 45L, 18L,
10L, 22L, 36L, 49L, 32L, 18L, 45L, 6L, 49L, 22L, 36L, 10L, 43L,
4L, 30L, 41L, 14L, 2L, 28L, 6L, 32L, 18L, 45L, 22L, 10L, 36L,
49L, 27L, 1L, 40L, 42L, 15L, 29L, 3L, 31L, 5L, 44L, 17L, 45L,
6L, 32L, 18L, 35L, 9L, 21L, 48L, 49L, 36L, 10L, 22L, 1L, 40L,
27L, 28L, 14L, 2L, 41L, 42L, 15L, 3L, 29L, 6L, 32L, 45L, 18L,
9L, 35L, 48L, 21L, 10L, 36L, 22L, 49L, 40L, 27L, 1L, 27L, 1L,
40L, 48L, 21L, 35L, 9L, 41L, 2L, 14L, 28L, 18L, 45L, 32L, 6L,
10L, 22L, 36L, 49L, 41L, 28L, 2L, 14L, 18L, 45L, 32L, 6L, 22L,
49L, 36L, 10L, 14L, 41L, 2L, 28L, 6L, 32L, 18L, 45L, 22L, 10L,
49L, 36L, 1L, 27L, 40L, 42L, 29L, 3L, 15L, 18L, 32L, 6L, 45L,
19L, 46L, 7L, 33L, 9L, 35L, 48L, 21L, 22L, 10L, 36L, 49L, 1L,
27L, 40L, 28L, 2L, 41L, 14L, 3L, 42L, 15L, 29L, 17L, 44L, 31L,
5L, 45L, 18L, 6L, 32L, 46L, 7L, 33L, 19L, 35L, 21L, 9L, 48L,
10L, 36L, 49L, 22L, 2L, 41L, 28L, 14L, 45L, 32L, 6L, 18L, 49L,
10L, 22L, 36L, 40L, 27L, 1L, 2L, 41L, 28L, 14L, 29L, 42L, 3L,
15L, 45L, 32L, 18L, 6L, 48L, 9L, 35L, 21L, 49L, 10L, 22L, 36L,
14L, 28L, 2L, 41L, 18L, 45L, 32L, 6L, 49L, 10L, 36L, 22L, 27L,
40L, 1L, 41L, 14L, 2L, 28L, 29L, 15L, 3L, 42L, 32L, 6L, 18L,
45L, 9L, 35L, 21L, 48L, 10L, 22L, 36L, 49L, 3L, 15L, 42L, 29L,
40L, 27L, 1L, 48L, 35L, 9L, 21L, 14L, 2L, 41L, 28L, 45L, 32L,
6L, 18L, 49L, 10L, 36L, 22L, 18L, 45L, 32L, 6L, 36L, 22L, 49L,
10L, 18L, 2L, 41L, 28L, 14L, 32L, 45L, 18L, 6L, 36L, 49L, 22L,
10L, 2L, 28L, 14L, 41L, 32L, 6L, 18L, 45L, 22L, 36L, 49L, 10L,
45L, 18L, 32L, 6L, 10L, 36L, 49L, 22L, 32L, 18L, 6L, 45L, 49L,
10L, 22L, 36L, 41L, 14L, 28L, 2L, 18L, 6L, 45L, 32L, 36L, 22L,
10L, 49L, 40L, 27L, 1L, 45L, 32L, 18L, 6L, 49L, 10L, 36L, 22L,
40L, 27L, 1L, 2L, 41L, 28L, 14L, 29L, 3L, 42L, 15L, 18L, 6L,
45L, 32L, 33L, 19L, 46L, 7L, 21L, 9L, 48L, 35L, 49L, 10L, 36L,
22L, 28L, 2L, 41L, 14L, 17L, 44L, 31L, 5L, 18L, 32L, 45L, 6L,
10L, 49L, 36L, 22L, 27L, 40L, 1L, 27L, 1L, 40L, 41L, 28L, 14L,
2L, 42L, 15L, 29L, 3L, 5L, 17L, 31L, 44L, 45L, 32L, 6L, 18L,
46L, 7L, 33L, 19L, 48L, 9L, 21L, 35L, 49L, 10L, 36L, 27L, 1L,
40L, 48L, 9L, 21L, 35L, 40L, 1L, 27L, 2L, 28L, 14L, 41L, 42L,
3L, 29L, 15L, 6L, 32L, 45L, 18L, 46L, 33L, 19L, 7L, 48L, 9L,
21L, 35L, 10L, 22L, 36L, 49L, 2L, 14L, 28L, 41L, 45L, 6L, 32L,
18L, 10L, 49L, 22L, 36L, 14L, 41L, 2L, 28L, 18L, 45L, 6L, 32L,
10L, 49L, 22L, 36L, 40L, 1L, 27L, 42L, 15L, 3L, 29L, 45L, 18L,
6L, 32L, 7L, 33L, 19L, 46L, 21L, 9L, 48L, 35L, 36L, 10L, 22L,
49L, 40L, 1L, 27L, 3L, 29L, 15L, 42L, 46L, 19L, 33L, 7L, 48L,
21L, 9L, 35L, 41L, 14L, 28L, 2L, 32L, 18L, 6L, 45L, 49L, 36L,
22L, 10L, 28L, 2L, 41L, 14L, 6L, 32L, 45L, 18L, 36L, 10L, 22L,
49L, 41L, 2L, 28L, 14L, 32L, 18L, 45L, 6L, 36L, 22L, 49L, 10L,
14L, 28L, 2L, 41L, 32L, 45L, 18L, 6L, 10L, 36L, 22L, 49L, 27L,
40L, 1L, 28L, 41L, 14L, 2L, 42L, 29L, 15L, 3L, 6L, 45L, 18L,
32L, 9L, 35L, 48L, 21L, 22L, 10L, 36L, 49L, 18L, 6L, 45L, 32L,
22L, 10L, 49L, 36L, 27L, 1L, 40L, 28L, 14L, 41L, 2L, 29L, 42L,
15L, 3L, 6L, 45L, 32L, 18L, 33L, 46L, 19L, 7L, 21L, 48L, 9L,
35L, 36L, 49L, 10L, 22L, 27L, 40L, 1L, 42L, 15L, 3L, 29L, 46L,
19L, 7L, 33L, 9L, 35L, 48L, 21L, 28L, 41L, 2L, 14L, 45L, 6L,
32L, 18L, 10L, 36L, 22L, 49L, 1L, 27L, 40L, 14L, 2L, 28L, 41L,
15L, 3L, 29L, 42L, 18L, 32L, 45L, 6L, 7L, 33L, 46L, 19L, 48L,
35L, 9L, 21L, 49L, 10L, 22L, 36L, 40L, 1L, 27L, 48L, 35L, 21L,
9L, 14L, 28L, 41L, 2L, 6L, 45L, 18L, 32L, 49L, 36L, 10L, 22L,
40L, 27L, 1L, 48L, 21L, 9L, 35L, 27L, 40L, 1L, 28L, 14L, 2L,
41L, 42L, 29L, 15L, 3L, 32L, 45L, 18L, 6L, 21L, 9L, 48L, 35L,
36L, 49L, 10L, 22L, 6L, 32L, 18L, 45L, 49L, 22L, 36L, 10L, 27L,
1L, 40L, 48L, 35L, 21L, 9L, 28L, 14L, 41L, 2L, 32L, 18L, 45L,
6L, 22L, 36L, 10L, 49L, 1L, 40L, 27L, 35L, 48L, 9L, 21L, 1L,
27L, 40L, 14L, 28L, 2L, 41L, 15L, 42L, 3L, 29L, 6L, 45L, 32L,
18L, 19L, 33L, 46L, 7L, 48L, 9L, 21L, 35L, 10L, 22L, 36L, 49L,
40L, 1L, 27L, 3L, 29L, 15L, 42L, 6L, 18L, 45L, 32L, 7L, 19L,
33L, 46L, 35L, 21L, 48L, 9L, 10L, 22L, 49L, 36L, 40L, 1L, 27L,
21L, 35L, 9L, 48L, 1L, 40L, 27L, 14L, 2L, 41L, 28L, 15L, 29L,
3L, 42L, 44L, 31L, 5L, 17L, 45L, 18L, 6L, 32L, 46L, 33L, 7L,
19L, 9L, 21L, 48L, 35L, 36L, 22L, 49L, 10L, 40L, 1L, 27L, 41L,
2L, 28L, 14L, 3L, 29L, 42L, 15L, 6L, 32L, 18L, 45L, 7L, 19L,
33L, 46L, 21L, 9L, 48L, 35L, 22L, 10L, 36L, 49L, 40L, 1L, 27L,
42L, 29L, 15L, 3L, 46L, 33L, 19L, 7L, 35L, 9L, 21L, 48L, 27L,
40L, 1L, 41L, 14L, 28L, 2L, 42L, 15L, 3L, 29L, 32L, 6L, 45L,
18L, 7L, 46L, 33L, 19L, 21L, 9L, 48L, 35L, 49L, 10L, 36L, 22L,
27L, 40L, 1L, 9L, 35L, 21L, 48L, 2L, 41L, 14L, 28L, 6L, 45L,
18L, 32L, 36L, 10L, 49L, 22L, 40L, 27L, 1L, 14L, 41L, 28L, 2L,
29L, 15L, 3L, 42L, 18L, 32L, 6L, 45L, 7L, 33L, 19L, 46L, 21L,
35L, 9L, 48L, 49L, 10L, 36L, 22L, 14L, 2L, 41L, 28L, 45L, 6L,
32L, 18L, 49L, 36L, 22L, 10L, 1L, 27L, 40L, 48L, 35L, 9L, 21L,
18L, 32L, 6L, 45L, 10L, 22L, 36L, 49L, 28L, 2L, 14L, 41L, 6L,
45L, 18L, 32L, 10L, 22L, 49L, 36L, 27L, 40L, 1L, 9L, 35L, 21L,
48L, 1L, 27L, 40L, 41L, 14L, 28L, 2L, 29L, 15L, 42L, 3L, 18L,
32L, 45L, 6L, 19L, 7L, 33L, 46L, 9L, 35L, 21L, 48L, 49L, 22L,
10L, 36L, 27L, 1L, 40L, 14L, 28L, 2L, 41L, 29L, 3L, 42L, 15L,
32L, 6L, 45L, 18L, 33L, 46L, 19L, 7L, 9L, 21L, 35L, 48L, 10L,
22L, 49L, 36L, 40L, 27L, 1L, 2L, 28L, 41L, 14L, 15L, 29L, 42L,
3L, 6L, 32L, 45L, 18L, 21L, 35L, 9L, 48L, 22L, 49L, 36L, 10L,
30L, 43L, 16L, 4L, 30L, 43L, 4L, 16L, 1L, 40L, 27L, 48L, 9L,
35L, 21L, 45L, 32L, 6L, 18L, 10L, 22L, 36L, 49L, 1L, 27L, 40L,
41L, 14L, 2L, 28L, 42L, 15L, 29L, 3L, 45L, 6L, 32L, 18L, 21L,
9L, 48L, 35L, 36L, 10L, 49L, 22L, 27L, 1L, 40L, 28L, 2L, 14L,
41L, 15L, 29L, 3L, 42L, 31L, 44L, 17L, 5L, 6L, 45L, 32L, 18L,
48L, 35L, 9L, 21L, 22L, 10L, 49L, 36L, 40L, 1L, 27L, 9L, 48L,
35L, 21L, 41L, 28L, 2L, 14L, 18L, 6L, 45L, 32L, 49L, 10L, 36L,
22L, 27L, 40L, 1L, 28L, 41L, 14L, 2L, 29L, 3L, 42L, 15L, 45L,
6L, 18L, 32L, 19L, 46L, 7L, 33L, 9L, 21L, 48L, 35L, 36L, 10L,
22L, 49L, 28L, 41L, 14L, 2L, 18L, 32L, 45L, 6L, 22L, 36L, 10L,
49L, 32L, 45L, 18L, 6L, 49L, 10L, 22L, 36L, 27L, 1L, 40L, 35L,
48L, 21L, 9L, 41L, 14L, 2L, 28L, 18L, 45L, 6L, 32L, 49L, 36L,
22L, 10L, 1L, 27L, 40L, 29L, 3L, 15L, 42L, 18L, 32L, 6L, 45L,
46L, 33L, 7L, 19L, 9L, 48L, 35L, 21L, 22L, 10L, 36L, 49L, 27L,
1L, 40L, 2L, 41L, 14L, 28L, 42L, 15L, 3L, 29L, 45L, 18L, 32L,
6L, 19L, 7L, 46L, 33L, 21L, 48L, 9L, 35L, 22L, 10L, 36L, 49L,
2L, 41L, 14L, 28L, 18L, 45L, 32L, 6L, 36L, 49L, 22L, 10L, 27L,
40L, 1L, 40L, 27L, 1L, 14L, 28L, 41L, 2L, 3L, 15L, 42L, 29L,
32L, 6L, 18L, 45L, 46L, 33L, 19L, 7L, 21L, 35L, 9L, 48L, 10L,
36L, 49L, 22L, 41L, 28L, 2L, 14L, 45L, 18L, 6L, 32L, 10L, 36L,
49L, 22L, 41L, 14L, 28L, 2L, 6L, 18L, 32L, 45L, 10L, 22L, 36L,
49L, 1L, 40L, 27L, 14L, 28L, 41L, 2L, 15L, 42L, 3L, 29L, 45L,
32L, 6L, 18L, 7L, 19L, 46L, 33L, 48L, 9L, 21L, 35L, 49L, 22L,
36L, 10L, 45L, 18L, 32L, 6L, 10L, 36L, 22L, 49L, 14L, 28L, 41L,
2L, 18L, 32L, 6L, 45L, 22L, 36L, 10L, 49L, 18L, 32L, 6L, 45L,
10L, 36L, 49L, 22L, 18L, 32L, 6L, 45L, 49L, 36L, 22L, 10L, 27L,
40L, 1L, 9L, 21L, 48L, 35L, 18L, 32L, 45L, 6L, 22L, 10L, 49L,
36L, 28L, 2L, 14L, 41L, 6L, 32L, 45L, 18L, 10L, 49L, 22L, 36L,
2L, 14L, 41L, 28L, 18L, 32L, 6L, 45L, 36L, 10L, 49L, 22L, 2L,
28L, 14L, 41L, 32L, 6L, 18L, 45L, 10L, 49L, 22L, 36L, 40L, 27L,
1L, 14L, 41L, 2L, 28L, 29L, 3L, 15L, 42L, 6L, 45L, 32L, 18L,
46L, 7L, 33L, 19L, 35L, 21L, 9L, 48L, 36L, 10L, 22L, 49L, 40L,
1L, 27L, 41L, 14L, 28L, 2L, 3L, 29L, 42L, 15L, 18L, 32L, 6L,
45L, 7L, 33L, 19L, 46L, 9L, 21L, 48L, 35L, 22L, 10L, 49L, 36L,
2L, 14L, 41L, 28L, 45L, 6L, 18L, 32L, 22L, 49L, 36L, 10L, 45L,
18L, 32L, 6L, 49L, 10L, 36L, 22L, 1L, 27L, 40L, 14L, 41L, 28L,
2L, 15L, 3L, 29L, 42L, 32L, 18L, 45L, 6L, 7L, 46L, 33L, 19L,
48L, 9L, 21L, 35L, 49L, 36L, 10L, 22L, 40L, 1L, 27L, 9L, 35L,
48L, 21L, 45L, 32L, 18L, 6L, 22L, 10L, 36L, 49L, 18L, 2L, 14L,
28L, 41L, 6L, 18L, 32L, 45L, 22L, 49L, 36L, 10L, 27L, 1L, 40L,
41L, 28L, 2L, 14L, 3L, 15L, 42L, 29L, 6L, 32L, 18L, 45L, 7L,
46L, 33L, 19L, 9L, 48L, 35L, 21L, 49L, 36L, 22L, 10L, 40L, 1L,
27L, 14L, 2L, 41L, 28L, 3L, 29L, 15L, 42L, 18L, 6L, 32L, 45L,
33L, 19L, 46L, 7L, 48L, 21L, 9L, 35L, 22L, 36L, 10L, 49L, 45L,
18L, 6L, 32L, 36L, 49L, 22L, 10L, 41L, 14L, 28L, 2L, 6L, 45L,
18L, 32L, 49L, 10L, 22L, 36L, 2L, 14L, 41L, 28L, 45L, 6L, 32L,
18L, 36L, 49L, 10L, 22L, 2L, 14L, 28L, 41L, 45L, 32L, 18L, 6L,
10L, 36L, 49L, 22L, 1L, 27L, 40L, 41L, 2L, 28L, 14L, 42L, 29L,
15L, 3L, 32L, 18L, 45L, 6L, 21L, 35L, 9L, 48L, 36L, 10L, 49L,
22L, 28L, 2L, 41L, 14L, 18L, 32L, 6L, 45L, 49L, 10L, 36L, 22L,
6L, 45L, 18L, 32L, 22L, 49L, 36L, 10L, 45L, 6L, 18L, 32L, 22L,
49L, 36L, 10L, 31L, 5L, 17L, 44L, 1L, 27L, 40L, 28L, 2L, 41L,
14L, 42L, 29L, 15L, 3L, 45L, 18L, 32L, 6L, 46L, 7L, 19L, 33L,
48L, 21L, 35L, 9L, 36L, 10L, 49L, 22L, 14L, 28L, 41L, 2L, 32L,
6L, 18L, 45L, 36L, 10L, 49L, 22L, 1L, 27L, 40L, 42L, 3L, 15L,
29L, 19L, 7L, 46L, 33L, 48L, 21L, 9L, 35L, 6L, 18L, 32L, 45L,
22L, 49L, 36L, 10L, 1L, 27L, 40L, 28L, 14L, 41L, 2L, 42L, 15L,
29L, 3L, 45L, 18L, 32L, 6L, 21L, 9L, 48L, 35L, 10L, 22L, 36L,
49L, 1L, 40L, 27L, 29L, 15L, 42L, 3L, 19L, 7L, 33L, 46L, 48L,
35L, 9L, 21L, 27L, 1L, 40L, 14L, 2L, 41L, 28L, 15L, 29L, 3L,
42L, 18L, 6L, 32L, 45L, 46L, 7L, 19L, 33L, 9L, 35L, 21L, 48L,
22L, 10L, 36L, 49L, 27L, 1L, 40L, 27L, 40L, 1L, 14L, 28L, 41L,
2L, 3L, 29L, 42L, 15L, 32L, 6L, 18L, 45L, 33L, 46L, 19L, 7L,
9L, 21L, 48L, 35L, 22L, 10L, 49L, 36L, 40L, 1L, 27L, 41L, 2L,
14L, 28L, 3L, 15L, 29L, 42L, 18L, 45L, 32L, 6L, 33L, 46L, 7L,
19L, 9L, 35L, 48L, 21L, 22L, 49L, 10L, 36L, 2L, 28L, 14L, 41L,
45L, 32L, 6L, 18L, 10L, 22L, 49L, 36L, 40L, 27L, 1L, 28L, 14L,
2L, 41L, 15L, 3L, 42L, 29L, 45L, 6L, 32L, 18L, 19L, 33L, 7L,
46L, 35L, 48L, 9L, 21L, 10L, 22L, 36L, 49L, 27L, 40L, 1L, 28L,
2L, 41L, 14L, 3L, 29L, 15L, 42L, 31L, 5L, 44L, 17L, 45L, 32L,
18L, 6L, 46L, 33L, 19L, 7L, 21L, 9L, 35L, 48L, 22L, 10L, 36L,
49L, 40L, 27L, 1L, 42L, 15L, 29L, 3L, 18L, 40L, 1L, 27L, 2L,
28L, 14L, 41L, 15L, 3L, 29L, 42L, 32L, 18L, 6L, 45L, 7L, 46L,
19L, 33L, 48L, 9L, 35L, 21L, 22L, 10L, 36L, 49L, 1L, 40L, 27L,
44L, 17L, 5L, 31L, 21L, 9L, 48L, 35L, 41L, 14L, 28L, 2L, 32L,
6L, 18L, 45L, 49L, 22L, 10L, 36L, 40L, 1L, 27L, 2L, 28L, 41L,
14L, 3L, 15L, 29L, 42L, 32L, 18L, 6L, 45L, 46L, 19L, 7L, 33L,
21L, 48L, 9L, 35L, 36L, 22L, 49L, 10L, 1L, 27L, 40L, 41L, 2L,
28L, 14L, 29L, 42L, 3L, 15L, 32L, 45L, 6L, 18L, 33L, 46L, 19L,
7L, 35L, 9L, 48L, 21L, 36L, 10L, 49L, 22L, 14L, 2L, 41L, 28L,
45L, 6L, 18L, 32L, 49L, 10L, 22L, 36L, 1L, 27L, 40L, 48L, 35L,
9L, 21L, 6L, 45L, 32L, 18L, 36L, 10L, 49L, 22L, 40L, 27L, 1L,
41L, 2L, 14L, 28L, 29L, 42L, 3L, 15L, 32L, 6L, 45L, 18L, 19L,
46L, 33L, 7L, 48L, 9L, 21L, 35L, 22L, 10L, 36L, 49L, 40L, 27L,
1L, 41L, 14L, 2L, 28L, 29L, 42L, 15L, 3L, 5L, 31L, 44L, 17L,
45L, 32L, 18L, 6L, 33L, 46L, 19L, 7L, 48L, 21L, 35L, 9L, 49L,
10L, 36L, 22L, 27L, 1L, 40L, 28L, 41L, 2L, 14L, 29L, 15L, 3L,
42L, 6L, 45L, 32L, 18L, 46L, 33L, 19L, 7L, 21L, 35L, 48L, 9L,
22L, 36L, 10L, 49L, 18L, 32L, 6L, 45L, 49L, 10L, 22L, 36L, 27L,
40L, 1L, 41L, 28L, 14L, 2L, 42L, 3L, 15L, 29L, 6L, 18L, 32L,
45L, 9L, 48L, 21L, 35L, 10L, 36L, 22L, 49L, 1L, 40L, 27L, 41L,
28L, 14L, 2L, 29L, 15L, 3L, 42L, 18L, 32L, 45L, 6L, 9L, 21L,
48L, 35L, 10L, 22L, 49L, 36L, 1L, 27L, 40L, 2L, 14L, 41L, 28L,
42L, 29L, 15L, 3L, 18L, 32L, 6L, 45L, 46L, 7L, 33L, 19L, 35L,
21L, 9L, 48L, 10L, 49L, 22L, 36L, 6L, 32L, 18L, 45L, 10L, 22L,
36L, 49L, 40L, 1L, 27L, 41L, 14L, 28L, 2L, 29L, 3L, 15L, 42L,
18L, 32L, 6L, 45L, 46L, 7L, 19L, 33L, 48L, 9L, 21L, 35L, 36L,
49L, 22L, 10L, 6L, 32L, 18L, 45L, 49L, 22L, 10L, 36L, 27L, 1L,
40L, 2L, 14L, 41L, 28L, 15L, 29L, 3L, 42L, 18L, 45L, 6L, 32L,
9L, 21L, 35L, 48L, 10L, 36L, 49L, 22L, 40L, 1L, 27L, 14L, 41L,
28L, 2L, 3L, 15L, 42L, 29L, 18L, 32L, 6L, 45L, 48L, 35L, 9L,
21L, 10L, 49L, 36L, 22L, 45L, 32L, 6L, 18L, 36L, 22L, 49L, 10L,
18L, 6L, 45L, 32L, 10L, 36L, 49L, 22L, 1L, 40L, 27L, 2L, 14L,
28L, 41L, 42L, 3L, 15L, 29L, 32L, 6L, 45L, 18L, 33L, 46L, 7L,
19L, 48L, 9L, 21L, 35L, 22L, 49L, 36L, 10L, 32L, 45L, 6L, 18L,
22L, 36L, 10L, 49L, 41L, 28L, 14L, 2L, 6L, 18L, 32L, 45L, 49L,
22L, 10L, 36L, 1L, 27L, 40L, 2L, 14L, 41L, 28L, 15L, 29L, 42L,
3L, 6L, 45L, 32L, 18L, 19L, 7L, 46L, 33L, 21L, 9L, 35L, 48L,
36L, 49L, 10L, 22L, 1L, 27L, 40L, 30L, 43L, 4L, 40L, 1L, 27L,
41L, 2L, 28L, 14L, 3L, 42L, 29L, 15L, 44L, 31L, 17L, 5L, 6L,
32L, 18L, 45L, 33L, 46L, 19L, 7L, 21L, 9L, 35L, 48L, 10L, 22L,
49L, 36L, 27L, 1L, 40L, 14L, 2L, 28L, 41L, 29L, 42L, 3L, 15L,
45L, 18L, 6L, 32L, 33L, 19L, 46L, 7L, 21L, 35L, 9L, 48L, 10L,
36L, 49L, 22L, 40L, 1L, 27L, 18L, 45L, 32L, 6L, 22L, 36L, 10L,
49L, 40L, 1L, 27L, 2L, 14L, 28L, 41L, 3L, 15L, 29L, 42L, 6L,
32L, 45L, 18L, 46L, 33L, 7L, 19L, 48L, 35L, 21L, 9L, 22L, 36L,
10L, 49L, 28L, 14L, 2L, 41L, 32L, 18L, 6L, 45L, 49L, 10L, 22L,
36L, 2L, 28L, 41L, 14L, 32L, 6L, 45L, 18L, 10L, 49L, 36L, 22L,
45L, 32L, 18L, 6L, 10L, 22L, 49L, 36L, 6L, 32L, 18L, 45L, 36L,
10L, 22L, 49L, 18L, 6L, 45L, 32L, 10L, 36L, 22L, 49L, 40L, 1L,
27L, 28L, 2L, 14L, 41L, 3L, 29L, 15L, 42L, 45L, 32L, 6L, 18L,
35L, 21L, 48L, 9L, 22L, 49L, 10L, 36L, 14L, 41L, 2L, 28L, 18L,
45L, 6L, 32L, 10L, 49L, 36L, 22L, 18L, 32L, 45L, 6L, 22L, 36L,
49L, 10L, 14L, 41L, 28L, 2L, 32L, 6L, 45L, 18L, 49L, 36L, 10L,
22L, 41L, 2L, 14L, 28L, 6L, 45L, 18L, 32L, 10L, 22L, 49L, 36L,
6L, 32L, 45L, 18L, 49L, 22L, 36L, 10L, 41L, 28L, 14L, 2L, 6L,
45L, 18L, 32L, 22L, 10L, 49L, 36L, 1L, 27L, 40L, 28L, 2L, 14L,
41L, 42L, 29L, 15L, 3L, 45L, 6L, 18L, 32L, 9L, 21L, 35L, 48L,
10L, 36L, 49L, 22L, 27L, 1L, 40L, 14L, 28L, 41L, 2L, 15L, 29L,
42L, 3L, 18L, 45L, 32L, 6L, 46L, 19L, 7L, 33L, 9L, 35L, 21L,
48L, 49L, 36L, 22L, 10L, 1L, 40L, 27L, 28L, 14L, 2L, 41L, 15L,
42L, 29L, 3L, 32L, 6L, 18L, 45L, 7L, 33L, 19L, 46L, 48L, 35L,
21L, 9L, 10L, 36L, 49L, 22L, 27L, 1L, 40L, 48L, 9L, 35L, 21L,
14L, 41L, 2L, 28L, 45L, 18L, 6L, 32L, 49L, 10L, 36L, 22L, 1L,
40L, 27L, 2L, 28L, 14L, 41L, 15L, 3L, 42L, 29L, 18L, 6L, 45L,
32L, 33L, 19L, 7L, 46L, 9L, 48L, 21L, 35L, 10L, 49L, 22L, 36L,
2L, 41L, 14L, 28L, 45L, 32L, 18L, 6L, 49L, 10L, 22L, 36L, 1L,
40L, 27L, 41L, 14L, 28L, 2L, 15L, 29L, 42L, 3L, 17L, 31L, 44L,
5L, 18L, 32L, 45L, 6L, 33L, 7L, 46L, 19L, 9L, 35L, 48L, 21L,
36L, 10L, 22L, 49L, 2L, 14L, 41L, 28L, 45L, 6L, 32L, 18L, 36L,
22L, 10L, 49L, 41L, 14L, 28L, 2L, 18L, 45L, 32L, 6L, 49L, 22L,
36L, 10L, 40L, 27L, 1L, 41L, 2L, 14L, 28L, 42L, 29L, 3L, 15L,
32L, 45L, 18L, 6L, 46L, 19L, 33L, 7L, 9L, 48L, 21L, 35L, 10L,
49L, 36L, 22L, 1L, 40L, 27L, 41L, 28L, 14L, 2L, 3L, 29L, 15L,
42L, 6L, 18L, 32L, 45L, 46L, 7L, 33L, 19L, 9L, 48L, 21L, 35L,
36L, 10L, 49L, 22L, 14L, 28L, 2L, 41L, 45L, 18L, 32L, 6L, 10L,
22L, 36L, 49L, 1L, 27L, 40L, 14L, 2L, 41L, 28L, 29L, 15L, 3L,
42L, 18L, 45L, 32L, 6L, 22L, 10L, 49L, 36L, 27L, 40L, 1L, 14L,
28L, 41L, 2L, 29L, 15L, 42L, 3L, 32L, 45L, 6L, 18L, 7L, 46L,
19L, 33L, 21L, 9L, 48L, 35L, 49L, 36L, 22L, 10L, 27L, 1L, 40L,
28L, 41L, 14L, 2L, 15L, 3L, 29L, 42L, 18L, 32L, 6L, 45L, 46L,
19L, 33L, 7L, 21L, 48L, 35L, 9L, 49L, 36L, 22L, 10L, 28L, 2L,
14L, 41L, 32L, 18L, 45L, 6L, 22L, 10L, 49L, 36L, 40L, 1L, 27L,
28L, 14L, 41L, 2L, 15L, 42L, 3L, 29L, 6L, 45L, 18L, 32L, 48L,
21L, 9L, 35L, 22L, 36L, 49L, 10L, 14L, 41L, 28L, 2L, 45L, 6L,
18L, 32L, 36L, 22L, 10L, 49L, 40L, 27L, 1L, 5L, 44L, 17L, 31L,
35L, 9L, 21L, 48L, 27L, 1L, 40L, 14L, 2L, 28L, 41L, 15L, 29L,
3L, 42L, 45L, 6L, 32L, 18L, 36L, 10L, 22L, 49L, 28L, 2L, 14L,
41L, 15L, 29L, 42L, 3L, 18L, 45L, 32L, 6L, 46L, 7L, 33L, 19L,
9L, 48L, 21L, 35L, 49L, 36L, 10L, 22L, 1L, 40L, 27L, 14L, 28L,
2L, 41L, 42L, 3L, 15L, 29L, 18L, 32L, 45L, 6L, 9L, 21L, 48L,
35L, 36L, 49L, 22L, 10L, 1L, 40L, 27L, 41L, 2L, 28L, 14L, 3L,
42L, 15L, 29L, 45L, 6L, 18L, 32L, 48L, 9L, 21L, 35L, 36L, 22L,
10L, 49L, 40L, 1L, 27L, 14L, 41L, 2L, 28L, 15L, 42L, 3L, 29L,
6L, 32L, 45L, 18L, 33L, 19L, 7L, 46L, 35L, 48L, 9L, 21L, 36L,
22L, 49L, 10L, 6L, 18L, 45L, 32L, 22L, 10L, 49L, 36L, 6L, 18L,
32L, 45L, 36L, 10L, 22L, 49L, 2L, 14L, 28L, 41L, 45L, 18L, 32L,
6L, 22L, 49L, 10L, 36L, 2L, 28L, 14L, 41L, 32L, 6L, 18L, 45L,
10L, 36L, 49L, 22L, 14L, 28L, 2L, 41L, 18L, 32L, 6L, 45L, 22L,
49L, 36L, 10L, 28L, 41L, 14L, 2L, 18L, 6L, 45L, 32L, 10L, 22L,
49L, 36L, 41L, 14L, 2L, 28L, 18L, 32L, 45L, 6L, 36L, 49L, 10L,
22L, 1L, 27L, 40L, 41L, 28L, 14L, 2L, 3L, 29L, 42L, 15L, 32L,
6L, 45L, 18L, 46L, 7L, 33L, 19L, 21L, 48L, 35L, 9L, 10L, 22L,
49L, 36L, 1L, 27L, 40L, 28L, 41L, 14L, 2L, 15L, 29L, 3L, 42L,
6L, 18L, 45L, 32L, 33L, 7L, 19L, 46L, 9L, 35L, 21L, 48L, 10L,
22L, 36L, 49L, 41L, 2L, 14L, 28L, 32L, 6L, 45L, 18L, 22L, 49L,
10L, 36L, 2L, 14L, 28L, 41L, 32L, 18L, 6L, 45L, 22L, 49L, 36L,
10L, 18L, 6L, 45L, 32L, 22L, 10L, 36L, 49L, 40L, 1L, 27L, 48L,
21L, 9L, 35L, 27L, 40L, 1L, 28L, 14L, 2L, 41L, 42L, 15L, 29L,
3L, 32L, 45L, 18L, 6L, 21L, 35L, 9L, 48L, 36L, 10L, 22L, 49L,
40L, 1L, 27L, 41L, 28L, 14L, 2L, 42L, 29L, 3L, 15L, 45L, 6L,
32L, 18L, 46L, 7L, 19L, 33L, 48L, 35L, 21L, 9L, 49L, 22L, 10L,
36L, 41L, 2L, 14L, 28L, 6L, 18L, 45L, 32L, 10L, 49L, 22L, 36L,
2L, 28L, 41L, 14L, 32L, 6L, 45L, 18L, 10L, 22L, 49L, 36L, 40L,
1L, 27L, 2L, 41L, 14L, 28L, 3L, 29L, 42L, 15L, 45L, 32L, 18L,
6L, 9L, 35L, 21L, 48L, 22L, 10L, 36L, 49L, 1L, 40L, 27L, 28L,
41L, 14L, 2L, 3L, 29L, 15L, 42L, 45L, 32L, 6L, 18L, 35L, 21L,
9L, 48L, 10L, 49L, 22L, 36L, 27L, 1L, 40L, 35L, 9L, 48L, 21L,
27L, 1L, 40L, 9L, 48L, 21L, 35L, 40L, 1L, 27L, 2L, 14L, 28L,
41L, 3L, 42L, 29L, 15L, 18L, 32L, 6L, 45L, 21L, 35L, 9L, 48L,
36L, 22L, 10L, 49L, 14L, 28L, 41L, 2L, 5L, 31L, 17L, 44L, 32L,
45L, 6L, 18L, 22L, 49L, 36L, 10L, 1L, 27L, 40L, 2L, 14L, 28L,
41L, 42L, 29L, 3L, 15L, 45L, 32L, 18L, 6L, 33L, 19L, 46L, 7L,
21L, 35L, 9L, 48L, 10L, 22L, 36L, 49L, 40L, 1L, 27L, 28L, 41L,
2L, 14L, 29L, 3L, 42L, 15L, 32L, 18L, 6L, 45L, 22L, 10L, 49L,
36L, 41L, 28L, 14L, 2L, 45L, 6L, 32L, 18L, 36L, 49L, 10L, 22L,
18L, 45L, 6L, 32L, 36L, 22L, 49L, 10L, 45L, 32L, 6L, 18L, 36L,
10L, 49L, 22L, 1L, 40L, 27L, 14L, 28L, 41L, 2L, 15L, 42L, 3L,
29L, 18L, 32L, 6L, 45L, 7L, 46L, 33L, 19L, 9L, 21L, 48L, 35L,
49L, 22L, 36L, 10L, 41L, 14L, 28L, 2L, 32L, 45L, 6L, 18L, 49L,
36L, 22L, 10L, 6L, 32L, 45L, 18L, 10L, 22L, 49L, 36L, 18L, 27L,
1L, 40L, 41L, 28L, 2L, 14L, 42L, 29L, 3L, 15L, 45L, 6L, 18L,
32L, 33L, 46L, 7L, 19L, 48L, 9L, 21L, 35L, 10L, 22L, 36L, 49L,
40L, 27L, 1L, 15L, 3L, 42L, 29L, 6L, 32L, 18L, 45L, 10L, 36L,
22L, 49L, 1L, 27L, 40L, 28L, 41L, 2L, 14L, 3L, 15L, 29L, 42L,
6L, 18L, 32L, 45L, 35L, 9L, 48L, 21L, 10L, 22L, 36L, 49L, 32L,
45L, 6L, 18L, 36L, 10L, 22L, 49L, 27L, 40L, 1L, 9L, 21L, 35L,
48L, 27L, 1L, 40L, 29L, 42L, 3L, 15L, 18L, 27L, 1L, 40L, 14L,
2L, 28L, 41L, 42L, 15L, 3L, 29L, 6L, 18L, 32L, 45L, 48L, 35L,
9L, 21L, 49L, 22L, 36L, 10L, 43L, 4L, 30L, 40L, 27L, 1L, 2L,
28L, 41L, 14L, 29L, 42L, 3L, 15L, 45L, 32L, 18L, 6L, 33L, 7L,
46L, 19L, 35L, 48L, 9L, 21L, 36L, 22L, 49L, 10L, 14L, 28L, 41L,
2L, 18L, 45L, 32L, 6L, 49L, 22L, 10L, 36L, 40L, 27L, 1L, 41L,
2L, 14L, 28L, 29L, 15L, 42L, 3L, 6L, 45L, 32L, 18L, 48L, 9L,
21L, 35L, 36L, 49L, 22L, 10L, 27L, 40L, 1L, 14L, 28L, 41L, 2L,
29L, 15L, 3L, 42L, 32L, 6L, 45L, 18L, 21L, 9L, 48L, 35L, 10L,
36L, 49L, 22L, 1L, 27L, 40L, 28L, 14L, 2L, 41L, 42L, 3L, 29L,
15L, 45L, 18L, 32L, 6L, 33L, 7L, 46L, 19L, 35L, 9L, 48L, 21L,
36L, 10L, 22L, 49L, 40L, 1L, 27L, 14L, 41L, 28L, 2L, 15L, 29L,
3L, 42L, 32L, 45L, 18L, 6L, 9L, 48L, 35L, 21L, 10L, 36L, 49L,
22L, 40L, 1L, 27L, 28L, 2L, 14L, 41L, 42L, 15L, 3L, 29L, 45L,
6L, 18L, 32L, 33L, 19L, 46L, 7L, 35L, 21L, 9L, 48L, 49L, 22L,
36L, 10L, 40L, 27L, 1L, 28L, 41L, 2L, 14L, 29L, 42L, 3L, 15L,
6L, 45L, 32L, 18L, 33L, 19L, 7L, 46L, 48L, 9L, 21L, 35L, 36L,
49L, 10L, 22L, 14L, 41L, 28L, 2L, 45L, 18L, 32L, 6L, 10L, 22L,
36L, 49L, 32L, 45L, 6L, 18L, 10L, 49L, 36L, 22L, 28L, 2L, 14L,
41L, 6L, 32L, 45L, 18L, 10L, 36L, 22L, 49L, 27L, 1L, 40L, 41L,
2L, 28L, 14L, 15L, 42L, 3L, 29L, 32L, 6L, 45L, 18L, 19L, 7L,
33L, 46L, 35L, 21L, 9L, 48L, 36L, 49L, 22L, 10L, 28L, 14L, 2L,
41L, 32L, 6L, 18L, 45L, 36L, 49L, 10L, 22L), .Label = c("Apr 06 - Jun 06",
"Apr 07 - Jun 07", "Apr 08 - Jun 08", "Apr 09 - Jun 09", "Apr 10 - Jun 10",
"Apr 11 - Jun 11", "Apr 12 - Jun 12", "Apr 13 - Jun 13", "Apr 14 - Jun 14",
"Apr 15 - Jun 15", "Apr 16 - Jun 16", "Apr 17 - Jun 17", "Apr 18 - Jun 18",
"Jan 07 - Mar 07", "Jan 08 - Mar 08", "Jan 09 - Mar 09", "Jan 10 - Mar 10",
"Jan 11 - Mar 11", "Jan 12 - Mar 12", "Jan 13 - Mar 13", "Jan 14 - Mar 14",
"Jan 15 - Mar 15", "Jan 16 - Mar 16", "Jan 17 - Mar 17", "Jan 18 - Mar 18",
"Jan 19 - Mar 19", "Jul 06 - Sep 06", "Jul 07 - Sep 07", "Jul 08 - Sep 08",
"Jul 09 - Sep 09", "Jul 10 - Sep 10", "Jul 11 - Sep 11", "Jul 12 - Sep 12",
"Jul 13 - Sep 13", "Jul 14 - Sep 14", "Jul 15 - Sep 15", "Jul 16 - Sep 16",
"Jul 17 - Sep 17", "Jul 18 - Sep 18", "Oct 06 - Dec 06", "Oct 07 - Dec 07",
"Oct 08 - Dec 08", "Oct 09 - Dec 09", "Oct 10 - Dec 10", "Oct 11 - Dec 11",
"Oct 12 - Dec 12", "Oct 13 - Dec 13", "Oct 14 - Dec 14", "Oct 15 - Dec 15",
"Oct 16 - Dec 16", "Oct 17 - Dec 17", "Oct 18 - Dec 18"), class = "factor")
Is there a way of turning this into a data object using lubridate? I tried different things like this:
a <- as.numeric(df$Period)
library(lubridate)
a <- quarter(a, with_year = TRUE)
And many similar iterations of this, but I cannot really get it tight.
Thanks!
Assuming the input is as shown below we can split it into from and to.
Then convert to yearmon class which represents year/month as year + fraction where fraction = 0 for Jan, 1/12 for Feb, ..., 11/12 for Dec (so for example adding 1/12 to such an object increments it by one month) and displays as shown.
We also convert to yearqtr class which represents quarters as year + fraction where the fraction is 0, 1/4, 1/2 and 3/4 for successive quarters so, for example, adding 1/4 to such an object increments it by one quarter.
These objects display as shown below.
Note that the question states that Period is character but the dput output shows it has factor class, not character.
library(dplyr)
library(tidyr)
library(zoo)
df <- data.frame(Period = c("Jul 06 - Sep 06", "Oct 06 - Dec 06",
"Apr 06 - Jun 06", "Apr 08 - Jun 08"))
df %>%
separate(Period, c("from", "to"), sep = " - ") %>%
mutate(from = as.yearmon(from, "%b %y"),
to = as.yearmon(to, "%b %y"),
year_qtr = as.yearqtr(to),
year = as.integer(to),
qtr = cycle(year_qtr),
from_date = as.Date(from),
to_date = as.Date(to, frac = 1))
giving:
from to year_qtr year qtr from_date to_date
1 Jul 2006 Sep 2006 2006 Q3 2006 3 2006-07-01 2006-09-30
2 Oct 2006 Dec 2006 2006 Q4 2006 4 2006-10-01 2006-12-31
3 Apr 2006 Jun 2006 2006 Q2 2006 2 2006-04-01 2006-06-30
4 Apr 2008 Jun 2008 2008 Q2 2008 2 2008-04-01 2008-06-30

Conditional replace values in a column

I am trying to replace some key numbers with their respective people names.
Despite my two attempts, I cannot change the numbers (characters) into names, any suggestions?
Here is what I tried so far:
setDT(df)[person == "447745939698" , person := "John"]
and
df <- df %>% mutate(person=ifelse(person=="447745939698","John",person))
Dataset:
structure(list(person = c("Pavel", "Anna", "Julian", "Bernardo",
"Bryony", "KJ", "Filippo", "Duncan", "‪447761633878‬", "Josh",
"Alex", "Berna", "Melina", "Martha", "‪447999592975‬", "‪48512044757‬",
"Don", "‪447404192025‬", "Sofia", "Jonas", "Chantal", "‪447441458269‬",
"‪447745939698‬", "Sungjoo", "‪447850449670‬", "Blanche",
"Vedo", "‪966554857666‬", "‪447787327724‬", "‪447407102816‬",
"‪447972826119‬", "‪447516428644‬", "‪447973747720‬",
"‪447383865362‬", "‪447478422564‬", "‪447543834973‬",
"Cris", "‪31642688469‬", "‪447921148041‬", "‪447865832098‬",
"Steve", "‪447492829467‬", "Andrea", "‪447878829919‬",
"‪447880747575‬", "‪34635960936‬", "‪447464871555‬",
"‪31640838890‬", "‪46707218515‬", "‪4528822826‬",
"‪393480848355‬", "‪447568552037‬", "‪4580211317‬",
"‪551198299‑2336‬", "‪447935988040‬", "‪447340827646‬"
)), class = c("data.table", "data.frame"), row.names = c(NA,
-56L), index = structure(integer(0), "`__person`" = c(11L,
43L, 2L, 12L, 4L, 26L, 5L, 21L, 37L, 17L, 8L, 7L, 20L, 10L, 3L,
6L, 14L, 13L, 1L, 19L, 41L, 24L, 27L, 48L, 38L, 46L, 51L, 56L,
40L, 34L, 30L, 18L, 47L, 35L, 22L, 42L, 32L, 36L, 52L, 23L, 9L,
29L, 44L, 45L, 25L, 39L, 55L, 31L, 33L, 15L, 50L, 53L, 49L, 16L,
54L, 28L)))

Subtract Values based on Multiple Grouping Factors

I have a dataset with phosphorus concentrations for 17 separate days (concentrations are cumulative, so increase from Day1 to Day102 in all cases). There are 22 different treatments (column = Trmt). Each Trmt has 3 Levels (Level = X, Y, Z). 2 measurements per Level for a total of 6 per Trmt.
My goal is to plot a 3-line graph of Days (x-axis; numeric) by Concentration (y-axis) using ggplot2. Data should be grouped by Trmt, Level and day for a total of 51 measurements (3 lines x 17 days).
My data looks as follows:
structure(list(Trmt = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 6L, 6L, 6L, 6L, 6L, 6L, 5L, 5L, 5L, 5L, 5L, 5L, 8L, 8L, 8L, 8L, 8L, 8L, 7L, 7L, 7L, 7L, 7L, 7L, 10L, 10L, 10L, 10L, 10L, 10L, 9L, 9L, 9L, 9L, 9L, 9L, 12L, 12L, 12L, 12L, 12L, 12L, 11L, 11L, 11L, 11L, 11L, 11L, 14L, 14L, 14L, 14L, 14L, 14L, 13L, 13L, 13L, 13L, 13L, 13L, 16L, 16L, 16L, 16L, 16L, 16L, 15L, 15L, 15L, 15L, 15L, 15L, 18L, 18L, 18L, 18L, 18L, 18L, 17L, 17L, 17L, 17L, 17L, 17L, 20L, 20L, 20L, 20L, 20L, 20L, 19L, 19L, 19L, 19L, 19L, 19L, 22L, 22L, 22L, 22L, 22L, 22L, 21L, 21L, 21L, 21L, 21L, 21L), .Label = c("A01nF", "A01yT", "A02nF", "A02yT", "A03nF", "A03yT", "A04nF", "A04yT", "A05nF", "A05yT", "A06nF", "A06yT", "A07nF", "A07yT", "A08nF", "A08yT", "A10nF", "A10yT", "A11nF", "A11yT", "A13nF", "A13yT"), class = "factor"), Level = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L), .Label = c("X", "Y", "Z"), class = "factor"), Day1 = c(3L, 1L, 4L, 2L, 4L, 2L, 5L, 4L, 1L, 2L, 5L, 1L, 5L, 2L, 5L, 5L, 3L, 5L, 3L, 3L, 1L, 4L, 1L, 1L, 5L, 4L, 1L, 5L, 4L, 5L, 3L, 5L, 3L, 5L, 3L, 4L, 2L, 4L, 2L, 4L, 3L, 1L, 1L, 3L, 1L, 3L, 1L, 5L, 2L, 4L, 4L, 3L, 1L, 4L, 4L, 1L, 4L, 1L, 2L, 5L, 1L, 5L, 1L, 2L, 4L, 4L, 4L, 4L, 2L, 4L, 5L, 5L, 4L, 1L, 3L, 2L, 3L, 5L, 4L, 3L, 2L, 3L, 5L, 4L, 1L, 3L, 4L, 3L, 3L, 5L, 3L, 1L, 1L, 4L, 4L, 5L, 1L, 4L, 4L, 4L, 1L, 4L, 5L, 5L, 1L, 5L, 3L, 1L, 4L, 1L, 4L, 5L, 5L, 3L, 3L, 2L, 4L, 5L, 3L, 2L, 1L, 5L, 5L, 2L, 2L, 3L, 4L, 3L, 4L, 2L, 2L, 4L), Day2 = c(10L, 9L, 7L, 7L, 6L, 7L, 10L, 9L, 10L, 6L, 10L, 7L, 8L, 9L, 8L, 9L, 7L, 10L, 7L, 10L, 6L, 8L, 6L, 8L, 8L, 8L, 10L, 6L, 8L, 8L, 6L, 10L, 7L, 10L, 7L, 10L, 6L, 6L, 7L, 9L, 8L, 10L, 8L, 7L, 9L, 8L, 6L, 9L, 7L, 9L, 8L, 6L, 6L, 8L, 10L, 7L, 8L, 6L, 8L, 8L, 6L, 9L, 10L, 6L, 8L, 7L, 9L, 7L, 8L, 10L, 10L, 6L, 7L, 10L, 9L, 9L, 8L, 9L, 6L, 8L, 6L, 8L, 6L, 9L, 10L, 7L, 7L, 7L, 8L, 7L, 8L, 10L, 7L, 8L, 9L, 6L, 8L, 9L, 8L, 9L, 6L, 7L, 10L, 9L, 10L, 7L, 6L, 9L, 9L, 9L, 6L, 10L, 9L, 8L, 9L, 7L, 10L, 7L, 10L, 9L, 6L, 8L, 9L, 8L, 9L, 6L, 6L, 10L, 9L, 8L, 8L, 7L), Day4 = c(11L, 12L, 14L, 11L, 15L, 15L, 12L, 11L, 15L, 12L, 15L, 12L, 12L, 11L, 15L, 15L, 13L, 11L, 13L, 14L, 12L, 11L, 13L, 12L, 15L, 15L, 14L, 11L, 15L, 11L, 12L, 11L, 13L, 11L, 12L, 13L, 13L, 14L, 13L, 15L, 14L, 15L, 12L, 14L, 11L, 13L, 15L, 11L, 12L, 13L, 11L, 15L, 11L, 13L, 11L, 11L, 14L, 12L, 14L, 15L, 11L, 12L, 15L, 12L, 13L, 12L, 14L, 12L, 11L, 13L, 12L, 12L, 11L, 15L, 13L, 12L, 11L, 12L, 13L, 14L, 14L, 14L, 13L, 12L, 15L, 12L, 15L, 15L, 12L, 13L, 12L, 12L, 12L, 14L, 13L, 13L, 14L, 11L, 12L, 11L, 15L, 11L, 11L, 11L, 14L, 11L, 12L, 15L, 15L, 11L, 12L, 14L, 15L, 14L, 14L, 12L, 14L, 13L, 15L, 15L, 14L, 13L, 12L, 15L, 15L, 11L, 13L, 12L, 11L, 13L, 12L, 14L), Day7 = c(19L, 17L, 17L, 20L, 17L, 19L, 18L, 19L, 17L, 20L, 16L, 20L, 19L, 18L, 20L, 19L, 17L, 16L, 18L, 18L, 17L, 18L, 19L, 18L, 17L, 19L, 17L, 20L, 19L, 20L, 19L, 20L, 17L, 18L, 20L, 19L, 20L, 18L, 18L, 20L, 18L, 20L, 17L, 19L, 17L, 19L, 17L, 17L, 20L, 18L, 18L, 17L, 16L, 18L, 20L, 16L, 17L, 19L, 16L, 19L, 16L, 17L, 16L, 20L, 16L, 19L, 19L, 17L, 17L, 17L, 20L, 19L, 18L, 16L, 20L, 17L, 19L, 16L, 18L, 19L, 16L, 19L, 20L, 20L, 16L, 16L, 18L, 17L, 16L, 18L, 16L, 17L, 16L, 18L, 20L, 16L, 16L, 20L, 20L, 16L, 20L, 18L, 17L, 19L, 18L, 18L, 19L, 19L, 16L, 18L, 19L, 19L, 17L, 17L, 18L, 18L, 20L, 18L, 20L, 20L, 18L, 19L, 19L, 16L, 16L, 17L, 20L, 16L, 17L, 18L, 16L, 20L), Day10 = c(24L, 23L, 23L, 21L, 21L, 23L, 21L, 21L, 22L, 25L, 21L, 23L, 21L, 25L, 25L, 25L, 24L, 22L, 25L, 24L, 21L, 23L, 24L, 23L, 23L, 22L, 23L, 22L, 22L, 25L, 25L, 22L, 21L, 24L, 25L, 23L, 23L, 23L, 24L, 23L, 25L, 23L, 21L, 23L, 22L, 24L, 22L, 23L, 24L, 22L, 25L, 23L, 23L, 21L, 25L, 24L, 24L, 25L, 25L, 25L, 22L, 23L, 21L, 22L, 24L, 22L, 23L, 22L, 24L, 22L, 21L, 22L, 23L, 21L, 25L, 25L, 22L, 21L, 25L, 24L, 22L, 21L, 25L, 24L, 21L, 24L, 25L, 22L, 23L, 22L, 24L, 23L, 25L, 25L, 23L, 25L, 22L, 23L, 23L, 23L, 22L, 25L, 22L, 23L, 24L, 25L, 22L, 21L, 21L, 22L, 23L, 24L, 21L, 24L, 23L, 23L, 25L, 24L, 25L, 23L, 22L, 25L, 25L, 25L, 21L, 22L, 23L, 21L, 24L, 24L, 25L, 21L), Day13 = c(29L, 29L, 26L, 27L, 30L, 30L, 30L, 26L, 30L, 29L, 30L, 27L, 26L, 29L, 28L, 26L, 30L, 28L, 29L, 27L, 28L, 26L, 29L, 28L, 30L, 26L, 27L, 30L, 26L, 29L, 26L, 28L, 29L, 28L, 29L, 28L, 27L, 27L, 28L, 26L, 26L, 27L, 27L, 29L, 27L, 29L, 27L, 30L, 26L, 27L, 30L, 26L, 29L, 29L, 27L, 29L, 26L, 29L, 28L, 28L, 29L, 30L, 28L, 30L, 30L, 30L, 28L, 29L, 28L, 27L, 28L, 27L, 27L, 28L, 27L, 30L, 27L, 30L, 27L, 28L, 29L, 27L, 30L, 29L, 30L, 30L, 26L, 30L, 29L, 30L, 27L, 26L, 27L, 27L, 28L, 26L, 30L, 28L, 30L, 30L, 30L, 30L, 26L, 28L, 27L, 26L, 29L, 26L, 29L, 26L, 30L, 29L, 30L, 26L, 27L, 30L, 29L, 30L, 27L, 30L, 28L, 26L, 30L, 27L, 30L, 26L, 28L, 29L, 26L, 28L, 28L, 26L), Day18 = c(32L, 31L, 32L, 31L, 31L, 34L, 32L, 34L, 32L, 33L, 31L, 34L, 35L, 34L, 34L, 32L, 33L, 35L, 32L, 35L, 31L, 31L, 33L, 33L, 32L, 31L, 32L, 31L, 32L, 34L, 33L, 33L, 34L, 31L, 35L, 35L, 31L, 34L, 32L, 32L, 34L, 33L, 34L, 33L, 33L, 35L, 35L, 31L, 35L, 31L, 33L, 34L, 31L, 33L, 34L, 32L, 32L, 33L, 31L, 32L, 35L, 34L, 31L, 32L, 34L, 35L, 34L, 31L, 34L, 33L, 35L, 35L, 31L, 32L, 35L, 34L, 31L, 32L, 32L, 33L, 32L, 35L, 32L, 32L, 35L, 33L, 34L, 32L, 34L, 35L, 34L, 33L, 33L, 31L, 31L, 31L, 35L, 34L, 33L, 32L, 33L, 33L, 33L, 35L, 34L, 33L, 31L, 34L, 34L, 34L, 34L, 33L, 33L, 31L, 31L, 31L, 33L, 33L, 35L, 32L, 32L, 31L, 31L, 32L, 33L, 32L, 34L, 34L, 31L, 35L, 31L, 35L), Day23 = c(39L, 40L, 38L, 37L, 37L, 38L, 37L, 36L, 37L, 36L, 36L, 38L, 40L, 38L, 37L, 36L, 36L, 40L, 40L, 40L, 40L, 39L, 40L, 36L, 38L, 36L, 36L, 37L, 38L, 37L, 36L, 37L, 39L, 39L, 38L, 38L, 37L, 40L, 36L, 38L, 37L, 40L, 36L, 37L, 39L, 38L, 38L, 38L, 40L, 38L, 37L, 36L, 38L, 36L, 36L, 36L, 39L, 40L, 39L, 37L, 39L, 39L, 37L, 36L, 37L, 39L, 39L, 37L, 36L, 37L, 40L, 36L, 39L, 40L, 39L, 40L, 39L, 38L, 39L, 40L, 37L, 40L, 38L, 38L, 38L, 40L, 40L, 36L, 39L, 39L, 39L, 39L, 38L, 37L, 37L, 36L, 37L, 39L, 37L, 40L, 40L, 40L, 38L, 38L, 39L, 38L, 36L, 37L, 36L, 36L, 40L, 39L, 39L, 39L, 36L, 39L, 38L, 40L, 36L, 37L, 38L, 38L, 36L, 37L, 39L, 36L, 40L, 40L, 39L, 38L, 37L, 38L), Day28 = c(42L, 43L, 43L, 44L, 44L, 44L, 42L, 42L, 43L, 42L, 45L, 43L, 43L, 43L, 42L, 44L, 42L, 44L, 45L, 44L, 44L, 45L, 44L, 41L, 41L, 42L, 44L, 44L, 44L, 45L, 43L, 42L, 43L, 42L, 41L, 44L, 43L, 43L, 42L, 42L, 44L, 42L, 42L, 42L, 45L, 44L, 45L, 42L, 43L, 45L, 45L, 44L, 41L, 42L, 42L, 41L, 44L, 44L, 44L, 44L, 42L, 45L, 41L, 42L, 45L, 43L, 44L, 45L, 44L, 42L, 41L, 43L, 41L, 44L, 43L, 41L, 45L, 42L, 45L, 41L, 45L, 41L, 45L, 42L, 45L, 42L, 45L, 45L, 41L, 41L, 43L, 41L, 41L, 42L, 43L, 41L, 42L, 44L, 43L, 45L, 41L, 41L, 44L, 41L, 44L, 43L, 43L, 45L, 44L, 41L, 44L, 43L, 42L, 45L, 45L, 41L, 45L, 42L, 41L, 44L, 41L, 41L, 41L, 43L, 41L, 41L, 45L, 41L, 42L, 45L, 41L, 44L), Day35 = c(50L, 50L, 50L, 50L, 48L, 46L, 50L, 46L, 48L, 50L, 50L, 50L, 46L, 49L, 46L, 47L, 49L, 49L, 48L, 49L, 46L, 47L, 49L, 46L, 49L, 50L, 49L, 46L, 49L, 50L, 46L, 48L, 50L, 46L, 50L, 48L, 46L, 48L, 50L, 50L, 47L, 47L, 47L, 47L, 47L, 49L, 48L, 46L, 46L, 48L, 50L, 46L, 49L, 48L, 46L, 49L, 50L, 49L, 48L, 48L, 48L, 50L, 49L, 47L, 48L, 50L, 50L, 46L, 47L, 46L, 48L, 48L, 48L, 47L, 49L, 48L, 49L, 46L, 47L, 50L, 47L, 50L, 47L, 47L, 46L, 46L, 47L, 50L, 49L, 49L, 48L, 47L, 46L, 50L, 46L, 50L, 50L, 46L, 47L, 47L, 49L, 50L, 50L, 46L, 47L, 50L, 47L, 48L, 46L, 50L, 49L, 46L, 46L, 50L, 50L, 49L, 46L, 49L, 46L, 46L, 46L, 48L, 47L, 47L, 50L, 47L, 46L, 48L, 50L, 48L, 46L, 46L), Day42 = c(52L, 51L, 53L, 53L, 54L, 55L, 55L, 54L, 52L, 51L, 55L, 51L, 54L, 53L, 53L, 55L, 54L, 55L, 51L, 51L, 55L, 54L, 54L, 53L, 55L, 53L, 52L, 53L, 53L, 51L, 54L, 54L, 55L, 53L, 54L, 55L, 51L, 51L, 54L, 52L, 51L, 51L, 55L, 54L, 54L, 52L, 52L, 55L, 55L, 51L, 55L, 52L, 55L, 51L, 53L, 52L, 53L, 54L, 51L, 54L, 54L, 55L, 52L, 54L, 52L, 52L, 51L, 52L, 55L, 52L, 54L, 51L, 52L, 55L, 51L, 52L, 55L, 54L, 52L, 53L, 53L, 52L, 55L, 51L, 51L, 55L, 52L, 55L, 55L, 55L, 53L, 52L, 53L, 54L, 52L, 52L, 52L, 52L, 53L, 51L, 54L, 54L, 51L, 53L, 55L, 51L, 54L, 54L, 54L, 53L, 53L, 54L, 54L, 55L, 52L, 52L, 54L, 51L, 52L, 51L, 51L, 55L, 52L, 51L, 51L, 53L, 54L, 51L, 51L, 54L, 55L, 52L), Day52 = c(59L, 57L, 56L, 58L, 59L, 59L, 57L, 59L, 57L, 56L, 58L, 58L, 60L, 59L, 56L, 56L, 60L, 57L, 60L, 57L, 59L, 56L, 60L, 59L, 59L, 56L, 60L, 58L, 60L, 57L, 57L, 60L, 56L, 57L, 59L, 60L, 56L, 58L, 57L, 57L, 58L, 58L, 59L, 56L, 58L, 56L, 57L, 60L, 58L, 59L, 58L, 56L, 56L, 57L, 60L, 59L, 60L, 58L, 59L, 60L, 57L, 60L, 59L, 57L, 60L, 56L, 57L, 56L, 58L, 60L, 56L, 58L, 56L, 60L, 57L, 57L, 57L, 60L, 58L, 59L, 58L, 60L, 59L, 58L, 56L, 56L, 58L, 57L, 60L, 56L, 58L, 56L, 57L, 58L, 58L, 60L, 59L, 60L, 59L, 59L, 59L, 57L, 57L, 60L, 59L, 57L, 57L, 58L, 59L, 57L, 59L, 58L, 60L, 59L, 56L, 57L, 57L, 56L, 57L, 60L, 58L, 57L, 56L, 59L, 59L, 59L, 57L, 57L, 58L, 56L, 58L, 60L), Day62 = c(67L, 65L, 68L, 65L, 69L, 70L, 69L, 66L, 65L, 70L, 70L, 65L, 67L, 68L, 65L, 67L, 65L, 66L, 66L, 68L, 68L, 66L, 65L, 67L, 66L, 69L, 69L, 69L, 68L, 67L, 66L, 69L, 65L, 65L, 69L, 66L, 69L, 68L, 69L, 67L, 65L, 69L, 69L, 69L, 70L, 67L, 65L, 65L, 65L, 66L, 66L, 69L, 68L, 66L, 67L, 66L, 70L, 70L, 70L, 69L, 70L, 70L, 67L, 66L, 65L, 69L, 67L, 66L, 70L, 70L, 70L, 65L, 66L, 67L, 66L, 66L, 67L, 68L, 70L, 67L, 69L, 66L, 67L, 65L, 70L, 65L, 70L, 66L, 66L, 69L, 68L, 65L, 65L, 67L, 68L, 67L, 69L, 68L, 69L, 66L, 68L, 70L, 69L, 68L, 70L, 66L, 69L, 66L, 66L, 67L, 65L, 69L, 69L, 67L, 70L, 65L, 70L, 69L, 66L, 68L, 67L, 68L, 66L, 65L, 67L, 70L, 66L, 67L, 66L, 67L, 67L, 70L), Day72 = c(74L, 74L, 71L, 75L, 74L, 71L, 75L, 71L, 75L, 71L, 72L, 72L, 75L, 73L, 75L, 74L, 74L, 74L, 71L, 74L, 72L, 71L, 71L, 74L, 74L, 73L, 72L, 73L, 71L, 71L, 75L, 72L, 73L, 74L, 75L, 73L, 71L, 71L, 74L, 71L, 73L, 75L, 75L, 74L, 71L, 75L, 74L, 72L, 72L, 71L, 72L, 75L, 73L, 74L, 71L, 75L, 75L, 73L, 72L, 73L, 73L, 72L, 75L, 72L, 71L, 72L, 73L, 72L, 72L, 74L, 72L, 72L, 73L, 75L, 74L, 75L, 73L, 74L, 75L, 72L, 75L, 73L, 71L, 71L, 72L, 74L, 72L, 75L, 71L, 71L, 71L, 73L, 72L, 71L, 75L, 75L, 74L, 73L, 71L, 71L, 72L, 71L, 71L, 74L, 72L, 73L, 71L, 75L, 74L, 75L, 74L, 73L, 73L, 73L, 72L, 75L, 73L, 71L, 71L, 72L, 72L, 71L, 71L, 71L, 72L, 73L, 75L, 75L, 72L, 73L, 75L, 75L), Day82 = c(76L, 78L, 78L, 78L, 79L, 77L, 78L, 77L, 80L, 79L, 80L, 76L, 76L, 80L, 80L, 80L, 78L, 78L, 78L, 78L, 80L, 78L, 76L, 79L, 76L, 77L, 76L, 79L, 78L, 76L, 76L, 79L, 79L, 77L, 77L, 77L, 78L, 78L, 80L, 77L, 77L, 76L, 77L, 79L, 78L, 78L, 78L, 80L, 79L, 76L, 79L, 77L, 76L, 80L, 78L, 77L, 79L, 80L, 77L, 80L, 78L, 79L, 78L, 76L, 76L, 79L, 77L, 77L, 78L, 78L, 79L, 78L, 78L, 78L, 80L, 79L, 78L, 77L, 78L, 78L, 78L, 79L, 80L, 77L, 77L, 80L, 77L, 80L, 77L, 76L, 77L, 76L, 77L, 77L, 80L, 79L, 77L, 78L, 80L, 80L, 79L, 80L, 79L, 79L, 78L, 76L, 76L, 79L, 79L, 80L, 79L, 78L, 76L, 79L, 77L, 77L, 76L, 76L, 78L, 78L, 79L, 78L, 76L, 78L, 79L, 76L, 77L, 78L, 76L, 79L, 78L, 77L), Day92 = c(85L, 84L, 85L, 85L, 83L, 82L, 83L, 82L, 85L, 85L, 82L, 85L, 85L, 85L, 81L, 81L, 84L, 81L, 85L, 82L, 85L, 84L, 81L, 82L, 83L, 82L, 84L, 84L, 81L, 85L, 83L, 85L, 82L, 81L, 83L, 83L, 85L, 83L, 81L, 83L, 82L, 84L, 83L, 83L, 82L, 85L, 85L, 82L, 82L, 82L, 85L, 81L, 81L, 82L, 82L, 84L, 81L, 85L, 81L, 82L, 81L, 81L, 85L, 83L, 81L, 83L, 83L, 84L, 83L, 85L, 85L, 83L, 81L, 85L, 81L, 84L, 83L, 83L, 85L, 83L, 82L, 82L, 82L, 83L, 82L, 83L, 81L, 84L, 83L, 84L, 82L, 83L, 81L, 83L, 81L, 82L, 82L, 82L, 85L, 85L, 84L, 81L, 81L, 81L, 84L, 81L, 84L, 81L, 81L, 84L, 84L, 83L, 83L, 82L, 82L, 81L, 85L, 85L, 82L, 83L, 81L, 83L, 82L, 84L, 83L, 82L, 84L, 81L, 83L, 82L, 84L, 85L), Day102 = c(89L, 88L, 88L, 90L, 88L, 90L, 87L, 88L, 89L, 87L, 90L, 86L, 86L, 89L, 86L, 89L, 90L, 88L, 87L, 88L, 88L, 87L, 90L, 86L, 90L, 87L, 88L, 89L, 88L, 90L, 88L, 87L, 89L, 90L, 88L, 87L, 89L, 88L, 87L, 86L, 90L, 86L, 89L, 89L, 90L, 88L, 90L, 86L, 88L, 88L, 90L, 89L, 88L, 88L, 90L, 87L, 88L, 88L, 87L, 90L, 89L, 87L, 90L, 90L, 86L, 87L, 86L, 90L, 88L, 87L, 86L, 88L, 90L, 86L, 89L, 90L, 87L, 87L, 88L, 86L, 86L, 89L, 89L, 86L, 87L, 86L, 86L, 88L, 88L, 88L, 89L, 90L, 88L, 86L, 88L, 88L, 87L, 88L, 90L, 89L, 89L, 86L, 90L, 89L, 89L, 88L, 90L, 88L, 86L, 90L, 90L, 87L, 89L, 90L, 90L, 88L, 88L, 89L, 90L, 88L, 90L, 90L, 87L, 89L, 90L, 90L, 90L, 89L, 86L, 88L, 89L, 88L)), class = "data.frame", row.names = c(NA, -132L))
Required libraries:
tidyr, plyr, ggplot2
The steps that I have taken so far are to:
Convert the data to long format (df = name of dataset):
Fig1 <- gather(df, day, phosphorus, Day1:Day102, factor_key=TRUE)
Change the factor day to numeric
df$day2 <-revalue(df$day, c("Day1"="1", "Day2"="2", "Day4"="4", "Day7"="7", "Day10"="10", "Day13"="13", "Day18"="18", "Day23" = "23","Day28" = "28", "Day35" = "35", "Day42" = "42", "Day52" = "52", "Day62" = "62", "Day72" = "72", "Day82" = "82", Day92" = "92", "Day102" = "102"))
and
df$day3 <- as.numeric(as.character(df$day2))
Group by Trmt, Level and day3
GroupedDF <- df %>% group_by(Trmt, Level, day3)
GroupedCO2M <- GroupedDF %>% summarise(disp = mean(phosphorus))
I would now like to subtract values by accounting for Trmt and Level, thus reducing the number of rows from 102 to 51. I would like to subtract 'yT' Trmt cases from respective 'nF' cases, uniquely for each Level (X, Y and Z). For example, subtract A01yT_X from A01nf_X, A01yT_Y from A01nf_Y, A01yT_Z from A01nf_Z etc. This should give a total of 51 points, 17 for each Level.
Here is a figure of what I have in mind:
Many thanks for any advice.
thanks for sharing the data. The data you have posted is a bit long, hence might not be able to totally copy and paste
Your data is in the wide format, and you need to find the average for each measurement between similar groups (defined by Day, Level, Treatment). So we can work on this in the wide format:
tmp <- Data %>% group_by(Trmt,Level) %>% summarise_all(mean)
> head(tmp)
# A tibble: 6 x 19
# Groups: Trmt [2]
Trmt Level Day1 Day2 Day4 Day7 Day10 Day13 Day18 Day23 Day28 Day35 Day42
<fct> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 A01nF X 3.5 8 12 19 23 29.5 32.5 36.5 42 50 53
2 A01nF Y 4.5 9.5 13 17.5 21 28 32.5 36 43.5 48 54.5
3 A01nF Z 1 8.5 13.5 18.5 22.5 28.5 33 37.5 43 49 51.5
4 A01yT X 2.5 8.5 11 19.5 22.5 28 31.5 38 43 50 52.5
5 A01yT Y 2.5 7.5 13.5 17 22 29.5 31 38.5 43.5 49 52.5
6 A01yT Z 3 7 14.5 18 23 28 33 38 43.5 48 54
This gives you the average for each Trmt,Level, and each column (Day) is average separately. Next step is to define the 2 subgroups under Trmt (nF and yT for A01,A02..), and for this we can introduce a subgroup called "site", which is Trmt without the nF,yT. Once you group your data.frame with this "site" and level, the first row will always be nF, and 2nd row yT, so taking the diff for all your Day columns within this grouping, will give you the difference. So we do it like this:
# need to ungroup Trmt to remove it later
tmp <- tmp%>% ungroup(Trmt) %>%
mutate(site = sub("[yn][TF]","",Trmt)) %>%
select(-Trmt) %>%
group_by(site,Level) %>%
summarize_all(diff)
Now you have the nF - yT values for each treatment, each level and each day
> head(tmp)
# A tibble: 6 x 19
# Groups: site [2]
site Level Day1 Day2 Day4 Day7 Day10 Day13 Day18 Day23 Day28 Day35 Day42
<chr> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 A01 X -1 0.5 -1 0.5 -0.5 -1.5 -1 1.5 1 0 -0.5
2 A01 Y -2 -2 0.5 -0.5 1 1.5 -1.5 2.5 0 1 -2
3 A01 Z 2 -1.5 1 -0.5 0.5 -0.5 0 0.5 0.5 -1 2.5
4 A02 X 1.5 1 1.5 1 -1 -1.5 2 -1.5 -1.5 -1 2
5 A02 Y 0.5 0 -1.5 -1 0.5 1.5 -0.5 -3 -1.5 0 1
6 A02 Z 4 2 1 0.5 1.5 0 2.5 0.5 0.5 1.5 0
Come the last part, which is to plot. We convert it to long and also make "Day", a numeric form of day.
plotdf <- gather(tmp, day, Diff, Day1:Day102, factor_key=TRUE) %>%
mutate(Day=as.numeric(sub("Day","",day)))
# and plot
ggplot(plotdf,aes(x=Day,y=Diff,col=Level,shape=Level)) + geom_line() + geom_point() + facet_wrap(~site) + scale_color_manual(values=c("grey10","grey40","grey80"))
Plot above shows the difference for each site. For diff that is the average across all sites:
meandf <- plotdf %>% group_by(Level,Day) %>% summarize(Diff=mean(Diff))
ggplot(meandf,aes(x=Day,y=Diff,col=Level,shape=Level)) + geom_line() + geom_point() + scale_color_manual(values=c("grey10","grey40","grey80"))
example dataset, subsetted for Day1, Day2 and Day4
Data <- structure(list(Trmt = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 1L,
1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L,
3L, 6L, 6L, 6L, 6L, 6L, 6L, 5L, 5L, 5L, 5L, 5L, 5L, 8L, 8L, 8L,
8L, 8L, 8L, 7L, 7L, 7L, 7L, 7L, 7L, 10L, 10L, 10L, 10L, 10L,
10L, 9L, 9L, 9L, 9L, 9L, 9L, 12L, 12L, 12L, 12L, 12L, 12L, 11L,
11L, 11L, 11L, 11L, 11L, 14L, 14L, 14L, 14L, 14L, 14L, 13L, 13L,
13L, 13L, 13L, 13L, 16L, 16L, 16L, 16L, 16L, 16L, 15L, 15L, 15L,
15L, 15L, 15L, 18L, 18L, 18L, 18L, 18L, 18L, 17L, 17L, 17L, 17L,
17L, 17L, 20L, 20L, 20L, 20L, 20L, 20L, 19L, 19L, 19L, 19L, 19L,
19L, 22L, 22L, 22L, 22L, 22L, 22L, 21L, 21L, 21L, 21L, 21L, 21L
), .Label = c("A01nF", "A01yT", "A02nF", "A02yT", "A03nF", "A03yT",
"A04nF", "A04yT", "A05nF", "A05yT", "A06nF", "A06yT", "A07nF",
"A07yT", "A08nF", "A08yT", "A10nF", "A10yT", "A11nF", "A11yT",
"A13nF", "A13yT"), class = "factor"), Level = structure(c(1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L), .Label = c("X", "Y", "Z"), class = "factor"), Day1 = c(3L,
1L, 4L, 2L, 4L, 2L, 5L, 4L, 1L, 2L, 5L, 1L, 5L, 2L, 5L, 5L, 3L,
5L, 3L, 3L, 1L, 4L, 1L, 1L, 5L, 4L, 1L, 5L, 4L, 5L, 3L, 5L, 3L,
5L, 3L, 4L, 2L, 4L, 2L, 4L, 3L, 1L, 1L, 3L, 1L, 3L, 1L, 5L, 2L,
4L, 4L, 3L, 1L, 4L, 4L, 1L, 4L, 1L, 2L, 5L, 1L, 5L, 1L, 2L, 4L,
4L, 4L, 4L, 2L, 4L, 5L, 5L, 4L, 1L, 3L, 2L, 3L, 5L, 4L, 3L, 2L,
3L, 5L, 4L, 1L, 3L, 4L, 3L, 3L, 5L, 3L, 1L, 1L, 4L, 4L, 5L, 1L,
4L, 4L, 4L, 1L, 4L, 5L, 5L, 1L, 5L, 3L, 1L, 4L, 1L, 4L, 5L, 5L,
3L, 3L, 2L, 4L, 5L, 3L, 2L, 1L, 5L, 5L, 2L, 2L, 3L, 4L, 3L, 4L,
2L, 2L, 4L), Day2 = c(10L, 9L, 7L, 7L, 6L, 7L, 10L, 9L, 10L,
6L, 10L, 7L, 8L, 9L, 8L, 9L, 7L, 10L, 7L, 10L, 6L, 8L, 6L, 8L,
8L, 8L, 10L, 6L, 8L, 8L, 6L, 10L, 7L, 10L, 7L, 10L, 6L, 6L, 7L,
9L, 8L, 10L, 8L, 7L, 9L, 8L, 6L, 9L, 7L, 9L, 8L, 6L, 6L, 8L,
10L, 7L, 8L, 6L, 8L, 8L, 6L, 9L, 10L, 6L, 8L, 7L, 9L, 7L, 8L,
10L, 10L, 6L, 7L, 10L, 9L, 9L, 8L, 9L, 6L, 8L, 6L, 8L, 6L, 9L,
10L, 7L, 7L, 7L, 8L, 7L, 8L, 10L, 7L, 8L, 9L, 6L, 8L, 9L, 8L,
9L, 6L, 7L, 10L, 9L, 10L, 7L, 6L, 9L, 9L, 9L, 6L, 10L, 9L, 8L,
9L, 7L, 10L, 7L, 10L, 9L, 6L, 8L, 9L, 8L, 9L, 6L, 6L, 10L, 9L,
8L, 8L, 7L), Day4 = c(11L, 12L, 14L, 11L, 15L, 15L, 12L, 11L,
15L, 12L, 15L, 12L, 12L, 11L, 15L, 15L, 13L, 11L, 13L, 14L, 12L,
11L, 13L, 12L, 15L, 15L, 14L, 11L, 15L, 11L, 12L, 11L, 13L, 11L,
12L, 13L, 13L, 14L, 13L, 15L, 14L, 15L, 12L, 14L, 11L, 13L, 15L,
11L, 12L, 13L, 11L, 15L, 11L, 13L, 11L, 11L, 14L, 12L, 14L, 15L,
11L, 12L, 15L, 12L, 13L, 12L, 14L, 12L, 11L, 13L, 12L, 12L, 11L,
15L, 13L, 12L, 11L, 12L, 13L, 14L, 14L, 14L, 13L, 12L, 15L, 12L,
15L, 15L, 12L, 13L, 12L, 12L, 12L, 14L, 13L, 13L, 14L, 11L, 12L,
11L, 15L, 11L, 11L, 11L, 14L, 11L, 12L, 15L, 15L, 11L, 12L, 14L,
15L, 14L, 14L, 12L, 14L, 13L, 15L, 15L, 14L, 13L, 12L, 15L, 15L,
11L, 13L, 12L, 11L, 13L, 12L, 14L)), class = "data.frame", row.names = c(NA,
-132L))

Create new column in R yes/no based off another column [duplicate]

This question already has answers here:
Create binary column (0/1) based on condition in another column
(2 answers)
Closed 3 years ago.
I am trying to create a new column in R (yes/no indicator) where if the data in X3 is >= 50 it would = 1(yes) or if <= 49 it would = 0(no).
I have tried various combinations of ifelse statements, I just cannot get it work. I need this step in order to construct my confidence interval.
dput (crime)
structure(list(Y = c(478L, 494L, 643L, 341L, 773L, 603L, 484L,
546L, 424L, 548L, 506L, 819L, 541L, 491L, 514L, 371L, 457L, 437L,
570L, 432L, 619L, 357L, 623L, 547L, 792L, 799L, 439L, 867L, 912L,
462L, 859L, 805L, 652L, 776L, 919L, 732L, 657L, 1419L, 989L,
821L, 1740L, 815L, 760L, 936L, 863L, 783L, 715L, 1504L, 1324L,
940L), X1 = c(184L, 213L, 347L, 565L, 327L, 260L, 325L, 102L,
38L, 226L, 137L, 369L, 109L, 809L, 29L, 245L, 118L, 148L, 387L,
98L, 608L, 218L, 254L, 697L, 827L, 693L, 448L, 942L, 1017L, 216L,
673L, 989L, 630L, 404L, 692L, 1517L, 879L, 631L, 1375L, 1139L,
3545L, 706L, 451L, 433L, 601L, 1024L, 457L, 1441L, 1022L, 1244L
), X2 = c(40L, 32L, 57L, 31L, 67L, 25L, 34L, 33L, 36L, 31L, 35L,
30L, 44L, 32L, 30L, 16L, 29L, 36L, 30L, 23L, 33L, 35L, 38L, 44L,
28L, 35L, 31L, 39L, 27L, 36L, 38L, 46L, 29L, 32L, 39L, 44L, 33L,
43L, 22L, 30L, 86L, 30L, 32L, 43L, 20L, 55L, 44L, 37L, 82L, 66L
), X3 = c(74L, 72L, 70L, 71L, 72L, 68L, 68L, 62L, 69L, 66L, 60L,
81L, 66L, 67L, 65L, 64L, 64L, 62L, 59L, 56L, 46L, 54L, 54L, 45L,
57L, 57L, 61L, 52L, 44L, 43L, 48L, 57L, 47L, 50L, 48L, 49L, 72L,
59L, 49L, 54L, 62L, 47L, 45L, 48L, 69L, 42L, 49L, 57L, 72L, 67L
), X4 = c(11L, 11L, 18L, 11L, 9L, 8L, 12L, 13L, 7L, 9L, 13L,
4L, 9L, 11L, 12L, 10L, 12L, 7L, 15L, 15L, 22L, 14L, 20L, 26L,
12L, 9L, 19L, 17L, 21L, 18L, 19L, 14L, 19L, 19L, 16L, 13L, 13L,
14L, 9L, 13L, 22L, 17L, 34L, 26L, 23L, 23L, 18L, 15L, 22L, 26L
), X5 = c(31L, 43L, 16L, 25L, 29L, 32L, 24L, 28L, 25L, 58L, 21L,
77L, 37L, 37L, 35L, 42L, 21L, 81L, 31L, 50L, 24L, 27L, 22L, 18L,
23L, 60L, 14L, 31L, 24L, 23L, 22L, 25L, 25L, 21L, 32L, 31L, 13L,
21L, 46L, 27L, 18L, 39L, 15L, 23L, 7L, 23L, 30L, 35L, 15L, 18L
), X6 = c(20L, 18L, 16L, 19L, 24L, 15L, 14L, 11L, 12L, 15L, 9L,
36L, 12L, 16L, 11L, 14L, 10L, 27L, 16L, 15L, 8L, 13L, 11L, 8L,
11L, 18L, 12L, 10L, 9L, 8L, 10L, 12L, 9L, 9L, 11L, 14L, 22L,
13L, 13L, 12L, 15L, 11L, 10L, 12L, 12L, 11L, 12L, 13L, 16L, 16L
), X7 = structure(list(Y = c(478L, 494L, 643L, 341L, 773L, 603L,
484L, 546L, 424L, 548L, 506L, 819L, 541L, 491L, 514L, 371L, 457L,
437L, 570L, 432L, 619L, 357L, 623L, 547L, 792L, 799L, 439L, 867L,
912L, 462L, 859L, 805L, 652L, 776L, 919L, 732L, 657L, 1419L,
989L, 821L, 1740L, 815L, 760L, 936L, 863L, 783L, 715L, 1504L,
1324L, 940L), X1 = c(184L, 213L, 347L, 565L, 327L, 260L, 325L,
102L, 38L, 226L, 137L, 369L, 109L, 809L, 29L, 245L, 118L, 148L,
387L, 98L, 608L, 218L, 254L, 697L, 827L, 693L, 448L, 942L, 1017L,
216L, 673L, 989L, 630L, 404L, 692L, 1517L, 879L, 631L, 1375L,
1139L, 3545L, 706L, 451L, 433L, 601L, 1024L, 457L, 1441L, 1022L,
1244L), X2 = c(40L, 32L, 57L, 31L, 67L, 25L, 34L, 33L, 36L, 31L,
35L, 30L, 44L, 32L, 30L, 16L, 29L, 36L, 30L, 23L, 33L, 35L, 38L,
44L, 28L, 35L, 31L, 39L, 27L, 36L, 38L, 46L, 29L, 32L, 39L, 44L,
33L, 43L, 22L, 30L, 86L, 30L, 32L, 43L, 20L, 55L, 44L, 37L, 82L,
66L), X3 = c(74L, 72L, 70L, 71L, 72L, 68L, 68L, 62L, 69L, 66L,
60L, 81L, 66L, 67L, 65L, 64L, 64L, 62L, 59L, 56L, 46L, 54L, 54L,
45L, 57L, 57L, 61L, 52L, 44L, 43L, 48L, 57L, 47L, 50L, 48L, 49L,
72L, 59L, 49L, 54L, 62L, 47L, 45L, 48L, 69L, 42L, 49L, 57L, 72L,
67L), X4 = c(11L, 11L, 18L, 11L, 9L, 8L, 12L, 13L, 7L, 9L, 13L,
4L, 9L, 11L, 12L, 10L, 12L, 7L, 15L, 15L, 22L, 14L, 20L, 26L,
12L, 9L, 19L, 17L, 21L, 18L, 19L, 14L, 19L, 19L, 16L, 13L, 13L,
14L, 9L, 13L, 22L, 17L, 34L, 26L, 23L, 23L, 18L, 15L, 22L, 26L
), X5 = c(31L, 43L, 16L, 25L, 29L, 32L, 24L, 28L, 25L, 58L, 21L,
77L, 37L, 37L, 35L, 42L, 21L, 81L, 31L, 50L, 24L, 27L, 22L, 18L,
23L, 60L, 14L, 31L, 24L, 23L, 22L, 25L, 25L, 21L, 32L, 31L, 13L,
21L, 46L, 27L, 18L, 39L, 15L, 23L, 7L, 23L, 30L, 35L, 15L, 18L
), X6 = c(20L, 18L, 16L, 19L, 24L, 15L, 14L, 11L, 12L, 15L, 9L,
36L, 12L, 16L, 11L, 14L, 10L, 27L, 16L, 15L, 8L, 13L, 11L, 8L,
11L, 18L, 12L, 10L, 9L, 8L, 10L, 12L, 9L, 9L, 11L, 14L, 22L,
13L, 13L, 12L, 15L, 11L, 10L, 12L, 12L, 11L, 12L, 13L, 16L, 16L
), X7 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0,
1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0)), row.names = c(NA, -50L), .Names = c("Y",
"X1", "X2", "X3", "X4", "X5", "X6", "X7"), class = "data.frame")), .Names = c("Y",
"X1", "X2", "X3", "X4", "X5", "X6", "X7"), row.names = c(NA,
-50L), class = "data.frame")
The dput didn't work. But I'd managed to dump the data from column Y and X3 in a dataset (called data) and use dplyr::mutate to do the transformation with a straightforward ifelse condition.
library(dplyr)
data <- data %>% mutate(X3_cat = ifelse(X3 >= 50, 1, 0))

R check if there is a letter and then multiply the value by -1

I have a dataframe (databycitydiff2) column as follows:
x
10N
20N
35S
25S
What I want to do is check if the letter at the end is N or S. If it is S, I want to remove the S and multiply the number by -1. If it is N, then I just want to remove the N.
I tried the following but it adds "-" to all values:
databycitydiff2$x<-gsub( "N", "", databycitydiff2$x)
databycitydiff2$x<-sub("^","-", gsub( "S", "", databycitydiff2$x))
What I get is:
x
-10
-20
-35
-25
What I want is:
x
10
20
-35
-25
Any suggestions? thank you!
Dput of the dataframe column (before i changed it to as.character):
structure(c(57L, 47L, 62L, 45L, 45L, 57L, 62L, 55L, 29L, 55L,
60L, 54L, 70L, 70L, 62L, 13L, 55L, 37L, 33L, 29L, 70L, 23L, 72L,
11L, 72L, 55L, 19L, 51L, 62L, 29L, 37L, 72L, 36L, 7L, 17L, 71L,
9L, 41L, 29L, 21L, 55L, 37L, 25L, 19L, 21L, 13L, 29L, 31L, 49L,
21L, 31L, 25L, 35L, 37L, 41L, 17L, 45L, 39L, 45L, 49L, 70L, 17L,
6L, 7L, 37L, 72L, 41L, 26L, 35L, 38L, 45L, 45L, 45L, 37L, 41L,
37L, 37L, 27L, 23L, 45L, 47L, 37L, 58L, 61L, 55L, 53L, 27L, 41L,
35L, 55L, 35L, 29L, 13L, 2L, 7L, 44L, 5L, 22L, 58L, 54L, 37L,
19L, 31L, 27L, 58L, 12L, 72L, 33L, 21L, 2L, 9L, 21L, 65L, 49L,
51L, 45L, 58L, 9L, 53L, 22L, 45L, 35L, 33L, 41L, 47L, 31L, 37L,
45L, 25L, 37L, 39L, 14L, 39L, 9L, 22L, 18L, 57L, 55L, 37L, 49L,
58L, 25L, 7L, 22L, 57L, 23L, 20L, 4L, 51L, 71L, 35L, 4L, 20L,
20L, 22L, 24L, 39L, 12L, 14L, 71L, 67L, 41L, 51L, 43L, 58L, 44L,
41L, 37L, 61L, 49L, 37L, 21L, 33L, 39L, 31L, 37L, 31L, 9L, 57L,
71L, 51L, 24L, 21L, 25L, 39L, 22L, 35L, 37L, 53L, 38L, 53L, 17L,
45L, 29L, 7L, 70L, 55L, 8L, 55L, 25L, 5L, 70L, 71L, 37L, 72L,
51L, 3L, 9L, 41L, 45L, 47L, 13L, 55L, 25L, 33L, 37L, 11L, 11L,
27L, 21L, 29L, 29L, 42L, 5L, 27L, 53L, 51L, 21L, 37L, 37L, 45L,
58L, 61L, 19L, 2L, 9L, 25L, 21L, 53L, 41L, 23L, 5L, 5L, 55L,
23L, 55L, 39L, 15L, 15L, 44L, 71L, 37L, 5L, 21L, 7L, 43L, 49L,
71L, 44L, 21L, 21L, 23L, 73L, 41L, 35L, 53L, 21L, 21L, 21L, 20L,
3L, 21L, 27L, 45L, 72L, 19L, 21L, 29L, 60L, 3L, 20L, 70L, 3L,
6L, 18L, 49L, 13L, 22L, 3L, 53L, 58L, 21L, 25L, 31L, 15L, 31L,
7L, 53L, 39L, 29L, 44L, 3L, 20L, 17L, 35L, 29L, 25L, 23L, 53L,
29L, 19L, 45L, 18L, 35L, 56L, 2L, 43L, 61L, 22L, 9L, 57L, 49L,
9L, 53L, 55L, 18L, 33L, 33L, 33L, 44L, 6L, 29L, 29L, 26L, 45L,
33L, 3L, 63L, 51L, 64L, 57L, 39L, 58L, 53L, 43L, 53L, 26L, 18L,
25L, 7L, 21L, 23L, 23L, 27L, 19L, 21L, 19L, 19L, 23L, 11L, 25L,
17L, 27L, 21L, 17L, 21L, 19L, 3L, 60L, 13L, 72L, 13L, 58L, 57L,
23L, 11L, 27L, 54L, 19L, 47L, 7L, 43L, 15L, 39L, 25L, 25L, 20L,
33L, 33L, 5L, 34L, 5L, 1L, 58L, 60L, 60L, 57L, 10L, 73L, 30L,
26L, 15L, 3L, 58L, 71L, 43L, 70L, 39L, 21L, 26L, 49L, 60L, 56L,
13L, 57L, 1L, 49L, 35L, 37L, 47L, 19L, 53L, 30L, 58L, 22L, 70L,
54L, 57L, 33L, 60L, 45L, 22L, 13L, 51L, 26L, 10L, 51L, 53L, 61L,
44L, 71L, 58L, 60L, 60L, 51L, 54L, 45L, 57L, 7L, 28L, 58L, 24L,
54L, 25L, 57L, 58L, 57L, 60L, 70L, 49L, 53L, 27L, 43L, 47L, 43L,
43L, 29L, 44L, 37L, 16L, 55L, 27L, 9L, 18L, 5L, 25L, 35L, 29L,
47L, 47L, 19L, 41L, 29L, 1L, 55L, 72L, 51L, 60L, 57L, 72L, 13L,
9L, 3L, 22L, 3L, 30L, 18L, 37L, 54L, 72L, 41L, 3L, 9L, 12L, 29L,
71L, 55L, 72L, 22L, 7L, 21L, 57L, 43L, 19L, 5L, 6L, 19L, 71L,
47L, 17L, 71L, 22L, 18L, 20L, 3L, 38L, 19L, 39L, 30L, 3L, 70L,
17L, 55L, 25L, 34L, 24L, 3L, 3L, 22L, 58L, 18L, 13L, 13L, 13L,
33L, 3L, 43L, 73L, 37L, 33L, 24L, 2L, 28L, 20L, 39L, 3L, 44L,
9L, 56L, 30L, 3L, 47L, 17L, 33L, 17L, 21L, 21L, 27L, 31L, 33L,
21L, 17L, 49L, 27L, 49L, 31L, 31L, 45L, 21L, 26L, 3L, 57L, 33L,
35L, 21L, 35L, 72L, 61L, 58L, 58L, 61L, 57L, 45L, 31L, 21L, 25L,
63L, 54L, 49L, 58L, 54L, 37L, 13L, 25L, 23L, 19L, 13L, 47L, 71L,
47L, 37L, 27L, 7L, 38L, 13L, 17L, 73L, 14L, 5L, 8L, 6L, 31L,
29L, 53L, 58L, 7L, 23L, 14L, 31L, 37L, 9L, 7L, 29L, 57L, 6L,
50L, 33L, 19L, 23L, 23L, 27L, 33L, 71L, 71L, 71L, 71L, 56L, 56L,
71L, 19L, 19L, 71L, 56L, 56L, 56L, 56L, 71L, 71L, 41L, 71L, 71L,
56L, 71L, 71L, 56L, 56L, 72L, 72L, 19L, 37L, 27L, 51L, 45L, 53L,
17L, 13L, 12L, 45L, 18L, 58L, 17L, 57L, 70L, 41L, 35L, 41L, 52L,
72L, 38L, 39L, 32L, 18L, 49L, 37L, 18L, 61L, 28L, 30L, 25L, 32L,
58L, 5L, 33L, 18L, 27L, 28L, 33L, 70L, 22L, 70L, 58L, 58L, 57L,
49L, 57L, 28L, 17L, 13L, 22L, 9L, 16L, 13L, 10L, 23L, 3L, 36L,
24L, 56L, 8L, 57L, 5L, 9L, 57L, 29L, 57L, 55L, 25L, 11L, 37L,
35L, 9L, 25L, 41L, 21L, 33L, 70L, 33L, 5L, 21L, 41L, 21L, 71L,
25L, 25L, 57L, 33L, 7L, 45L, 45L, 61L, 70L, 7L, 41L, 31L, 41L,
72L, 53L, 29L, 23L, 49L, 31L, 27L, 27L, 13L, 39L, 73L, 33L, 41L,
25L, 71L, 29L, 31L, 47L, 60L, 45L, 3L, 47L, 21L, 31L, 33L, 39L,
21L, 21L, 25L, 9L, 25L, 17L, 22L, 27L, 51L, 70L, 53L, 25L, 60L,
23L, 3L, 41L, 9L, 3L, 18L, 55L, 3L, 33L, 56L, 23L, 21L, 17L,
45L, 33L, 39L, 58L, 58L, 39L, 55L, 43L, 20L, 35L, 57L, 49L, 23L,
60L, 58L, 57L, 21L, 33L, 72L, 15L, 62L, 52L, 47L, 22L, 23L, 30L,
19L, 21L, 37L, 45L, 41L, 62L, 34L, 35L, 57L, 47L, 37L, 17L, 43L,
70L, 61L, 47L, 45L, 60L, 58L, 72L, 70L, 58L, 29L, 3L, 31L, 35L,
31L, 9L, 72L, 45L, 60L, 1L, 61L, 51L, 45L, 11L, 22L, 58L, 19L,
57L, 58L, 31L, 70L, 55L, 57L, 54L, 5L, 41L, 41L, 33L, 9L, 45L,
33L, 41L, 37L, 18L, 64L, 57L, 27L, 25L, 49L, 39L, 57L, 29L, 54L,
39L, 31L, 25L, 27L, 21L, 27L, 25L, 35L, 6L, 45L, 21L, 24L, 49L,
22L, 35L, 20L, 25L, 31L, 47L, 49L, 15L, 28L, 70L, 51L, 45L, 35L,
49L, 26L, 45L, 25L, 45L, 33L, 44L, 21L, 24L, 18L, 22L, 22L, 57L,
72L, 53L, 39L, 21L, 37L, 37L, 45L, 35L, 35L, 37L, 35L, 37L, 37L,
35L, 29L, 33L, 37L, 5L, 45L, 47L, 33L, 51L, 25L, 63L, 58L, 23L,
24L, 9L, 55L, 29L, 51L, 71L, 21L, 21L, 29L, 25L, 9L, 25L, 37L,
19L, 73L, 33L, 33L, 33L, 72L, 71L, 25L, 7L, 23L, 39L, 21L, 33L,
70L, 70L, 60L, 60L, 45L, 40L, 21L, 58L, 43L, 25L, 51L, 49L, 57L,
36L, 70L, 57L, 45L, 27L, 23L, 49L, 33L, 57L, 70L, 43L, 45L, 29L,
61L, 63L, 35L, 57L, 58L, 21L, 12L, 31L, 28L, 16L, 3L, 58L, 39L,
25L, 19L, 5L, 49L, 25L, 37L, 1L, 58L, 14L, 39L, 33L, 47L, 30L,
53L, 49L, 37L, 51L, 71L, 60L, 30L, 3L, 17L, 25L, 72L, 31L, 33L,
21L, 17L, 18L, 24L, 22L, 3L, 22L, 22L, 9L, 9L, 3L, 16L, 27L,
5L, 11L, 49L, 23L, 25L, 33L, 33L, 11L, 15L, 23L, 9L, 11L, 27L,
5L, 25L, 25L, 18L, 53L, 45L, 19L, 17L, 58L, 58L, 35L, 21L, 45L,
37L, 37L, 5L, 31L, 58L, 9L, 19L, 41L, 45L, 33L, 23L, 54L, 53L,
21L, 23L, 45L, 19L, 29L, 49L, 21L, 57L, 35L, 35L, 60L, 47L, 47L,
58L, 37L, 35L, 37L, 41L, 29L, 19L, 58L, 29L, 33L, 21L, 27L, 14L,
51L, 25L, 72L, 29L, 45L, 7L, 70L, 27L, 39L, 21L, 37L, 31L, 53L,
54L, 57L, 54L, 64L, 37L, 51L, 39L, 25L, 11L, 35L, 29L, 58L, 35L,
25L, 13L, 41L, 35L, 58L, 35L, 7L, 37L, 35L, 37L, 45L, 35L, 29L,
37L, 3L, 48L, 35L, 45L, 17L, 25L, 19L, 51L, 29L, 54L, 22L, 21L,
31L, 9L, 5L, 37L, 29L, 60L, 23L, 23L, 23L, 4L, 47L, 35L, 27L,
33L, 33L, 8L, 6L, 41L, 21L, 27L, 29L, 9L, 60L, 11L, 39L, 21L,
17L, 21L, 51L, 53L, 21L, 33L, 35L, 31L, 23L, 53L, 70L, 43L, 35L,
1L, 7L, 18L, 8L, 11L, 35L, 37L, 35L, 37L, 70L, 72L, 13L, 37L,
70L, 70L, 70L, 70L, 70L, 70L, 35L, 70L, 55L, 70L, 33L, 70L, 44L,
72L, 10L, 72L, 70L, 3L, 72L, 35L, 56L, 23L, 35L, 22L, 41L, 41L,
21L, 56L, 41L, 35L, 54L, 23L, 70L, 53L, 18L, 43L, 58L, 18L, 44L,
35L, 25L, 17L, 33L, 37L, 71L, 58L, 37L, 33L, 33L, 70L, 37L, 37L,
70L, 41L, 15L, 37L, 33L, 31L, 39L, 45L, 22L, 10L, 55L, 22L, 26L,
35L, 22L, 22L, 22L, 22L, 21L, 22L, 62L, 39L, 35L, 37L, 70L, 17L,
62L, 39L, 45L, 35L, 39L, 20L, 21L, 73L, 22L, 33L, 29L, 27L, 72L,
29L, 27L, 25L, 56L, 35L, 31L, 72L, 17L, 25L, 23L, 1L, 2L, 33L,
19L, 21L, 21L, 22L, 26L, 33L, 31L, 25L, 73L, 8L, 37L, 45L, 31L,
19L, 31L, 23L, 33L, 27L, 4L, 53L, 25L, 21L, 31L, 31L, 49L, 27L,
37L, 35L, 31L, 41L, 21L, 5L, 19L, 21L, 33L, 49L, 72L, 70L, 37L,
39L, 23L, 29L, 29L, 29L, 45L, 45L, 45L, 27L, 27L, 49L, 29L, 45L,
49L, 13L, 51L, 71L, 25L, 39L, 26L, 1L, 26L, 45L, 55L, 71L, 3L,
73L, 31L, 71L, 43L, 20L, 24L, 10L, 19L, 22L, 41L, 3L, 35L, 8L,
14L, 3L, 39L, 35L, 25L, 29L, 21L, 37L, 11L, 35L, 56L, 61L, 58L,
39L, 70L, 21L, 60L, 17L, 37L, 35L, 31L, 21L, 61L, 31L, 1L, 57L,
56L, 7L, 21L, 3L, 70L, 3L, 5L, 25L, 41L, 61L, 21L, 7L, 11L, 23L,
37L, 39L, 51L, 71L, 56L, 13L, 35L, 54L, 29L, 35L, 41L, 35L, 29L,
37L, 9L, 57L, 33L, 35L, 37L, 31L, 27L, 23L, 57L, 7L, 73L, 61L,
37L, 37L, 35L, 37L, 41L, 61L, 71L, 53L, 71L, 71L, 23L, 54L, 71L,
61L, 44L, 35L, 51L, 29L, 35L, 54L, 27L, 11L, 19L, 29L, 31L, 27L,
19L, 21L, 9L, 53L, 61L, 7L, 33L, 11L, 33L, 29L, 39L, 45L, 21L,
27L, 33L, 27L, 60L, 57L, 57L, 16L, 44L, 56L, 31L, 28L, 3L, 16L,
13L, 60L, 44L, 37L, 63L, 54L, 37L, 1L, 15L, 35L, 72L, 35L, 49L,
2L, 2L, 35L, 49L, 49L, 6L, 61L, 15L, 71L, 26L, 15L, 37L, 35L,
57L, 3L, 37L, 37L, 33L, 72L, 37L, 7L, 11L, 72L, 61L, 64L, 35L,
37L, 57L, 37L, 39L, 19L, 72L, 39L, 45L, 55L, 37L, 54L, 62L, 60L,
29L, 23L, 55L, 55L, 70L, 5L, 62L, 70L, 49L, 51L, 61L, 57L, 54L,
56L, 21L, 28L, 26L, 53L, 15L, 55L, 43L, 1L, 33L, 6L, 55L, 21L,
37L, 47L, 70L, 43L, 3L, 23L, 4L, 35L, 35L, 61L, 58L, 33L, 35L,
7L, 35L, 49L, 14L, 58L, 9L, 23L, 36L, 30L, 13L, 30L, 13L, 41L,
60L, 17L, 29L, 72L, 72L, 28L, 55L, 55L, 31L, 37L, 37L, 41L, 27L,
25L, 27L, 24L, 13L, 35L, 41L, 47L, 37L, 13L, 33L, 3L, 27L, 27L,
27L, 19L, 37L, 29L, 21L, 45L, 13L, 51L, 71L, 54L, 53L, 5L, 60L,
45L, 7L, 49L, 57L, 58L, 58L, 57L, 25L, 71L, 35L, 27L, 60L, 29L,
71L, 57L, 39L, 57L, 19L, 23L, 37L, 45L, 1L, 21L, 8L, 4L, 57L,
8L, 6L, 20L, 51L, 27L, 45L, 37L, 27L, 18L, 37L, 37L, 41L, 37L,
54L, 7L, 58L, 15L, 41L, 35L, 21L, 23L, 60L, 14L, 51L, 45L, 2L,
6L, 47L, 44L, 47L, 22L, 33L, 3L, 51L, 53L, 47L, 23L, 27L, 35L,
25L, 17L, 3L, 27L, 9L, 39L, 55L, 47L, 46L, 31L, 39L, 73L, 8L,
10L, 33L, 57L, 6L, 7L, 23L, 31L, 54L, 73L, 33L, 35L, 27L, 24L,
10L, 58L, 25L, 29L, 12L, 57L, 51L, 61L, 37L, 37L, 19L, 57L, 57L,
58L, 45L, 31L, 57L, 23L, 9L, 20L, 1L, 4L, 44L, 31L, 37L, 9L,
7L, 21L, 47L, 71L, 7L, 45L, 3L, 22L, 72L, 58L, 71L, 60L, 37L,
10L, 11L, 21L, 5L, 5L, 57L, 5L, 71L, 56L, 9L, 47L, 53L, 70L,
43L, 72L, 3L, 71L, 39L, 17L, 29L, 61L, 9L, 70L, 1L, 5L, 25L,
16L, 37L, 47L, 19L, 3L, 33L, 23L, 5L, 7L, 9L, 41L, 55L, 54L,
2L, 13L, 26L, 19L, 26L, 40L, 56L, 3L, 44L, 3L, 7L, 39L, 20L,
41L, 70L, 37L, 35L, 3L, 22L, 37L, 3L, 31L, 47L, 44L, 29L, 5L,
30L, 37L, 31L, 56L, 25L, 21L, 45L, 73L, 27L, 26L, 35L, 37L, 37L,
35L, 3L, 25L, 22L, 11L, 22L, 49L, 19L, 21L, 58L, 1L, 73L, 55L,
7L, 56L, 19L, 43L, 55L, 17L, 19L, 7L, 15L, 40L, 35L, 34L, 41L,
34L, 5L, 37L, 33L, 33L, 39L, 29L, 13L, 56L, 54L, 33L, 17L, 9L,
60L, 25L, 37L, 31L, 61L, 26L, 60L, 26L, 16L, 51L, 47L, 13L, 35L,
37L, 72L, 51L, 60L, 25L, 43L, 23L, 23L, 37L, 35L, 53L, 33L, 37L,
9L, 31L, 31L, 70L, 49L, 39L, 57L, 31L, 15L, 22L, 71L, 3L, 44L,
25L, 70L, 9L, 72L, 25L, 12L, 36L, 33L, 49L, 51L, 19L, 51L, 9L,
27L, 70L, 17L, 25L, 35L, 35L, 9L, 71L, 21L, 61L, 44L, 56L, 47L,
25L, 72L, 3L, 49L, 6L, 53L, 29L, 23L, 53L, 39L, 31L, 68L, 61L,
21L, 37L, 2L, 14L, 29L, 29L, 25L, 16L, 71L, 3L, 19L, 61L, 49L,
10L, 21L, 35L, 7L, 39L, 37L, 21L, 72L, 35L, 19L, 21L, 2L, 11L,
47L, 7L, 9L, 72L, 2L, 47L, 11L, 17L, 45L, 10L, 57L, 53L, 27L,
31L, 54L, 13L, 19L, 9L, 27L, 31L, 21L, 45L, 53L, 31L, 21L, 33L,
45L, 45L, 37L, 21L, 37L, 21L, 37L, 23L, 56L, 17L, 21L, 41L, 17L,
23L, 25L, 39L, 49L, 72L, 8L, 61L, 65L, 70L, 54L, 29L, 15L, 24L,
33L, 42L, 57L, 49L, 27L, 45L, 29L, 45L, 45L, 28L, 61L, 58L, 39L,
35L, 37L, 5L, 17L, 70L, 7L, 5L, 7L, 49L, 17L, 26L, 39L, 35L,
37L, 58L, 22L, 29L, 47L, 35L, 35L, 22L, 13L, 61L, 64L, 62L, 62L,
55L, 55L, 55L, 33L, 37L, 31L, 61L, 7L, 37L, 69L, 35L, 37L, 38L,
58L, 35L, 58L, 4L, 60L, 13L, 20L, 22L, 51L, 51L, 30L, 61L, 53L,
60L, 60L, 49L, 61L, 57L, 70L, 7L, 27L, 47L, 35L, 54L, 53L, 70L,
39L, 11L, 57L, 47L, 61L, 55L, 27L, 55L, 33L, 3L, 37L, 61L, 51L,
61L, 72L, 57L, 35L, 72L, 31L, 35L, 37L, 43L, 60L, 41L, 58L, 60L,
71L, 54L, 9L, 60L, 45L, 37L, 61L, 33L, 70L, 9L, 55L, 35L, 43L,
57L, 58L, 53L, 25L, 33L, 45L, 61L, 13L, 26L, 53L, 27L, 55L, 60L,
57L, 39L, 14L, 22L, 49L, 70L, 64L, 39L, 58L, 46L, 57L, 37L, 47L,
51L, 70L, 5L, 67L, 41L, 47L, 55L, 70L, 58L, 35L, 37L, 70L, 39L,
12L, 73L, 51L, 13L, 36L, 21L, 71L, 17L, 71L, 2L, 58L, 51L, 70L,
7L, 19L, 29L, 3L, 23L, 16L, 39L, 28L, 25L, 7L, 41L, 17L, 4L,
35L, 43L, 3L, 2L, 27L, 56L, 47L, 56L, 72L, 23L, 61L, 71L, 21L,
29L, 13L, 25L, 37L, 72L, 55L, 32L, 24L, 17L, 54L, 49L, 16L, 56L,
41L, 56L, 35L, 56L, 71L, 1L, 28L, 1L, 71L, 21L, 23L, 45L, 33L,
11L, 71L, 29L, 23L, 14L, 71L, 58L, 54L, 2L, 71L, 41L, 32L, 71L,
8L, 25L, 60L, 45L, 43L, 55L, 39L, 63L, 47L, 32L, 47L, 62L, 47L,
35L, 15L, 9L, 3L, 58L, 22L, 73L, 61L, 60L, 65L, 54L, 31L, 22L,
3L, 41L, 11L, 5L, 33L, 7L, 53L, 27L, 30L, 22L, 27L, 13L, 19L,
22L, 3L, 23L, 35L, 37L, 21L, 21L, 27L, 58L, 22L, 49L, 45L, 56L,
7L, 33L, 49L, 58L, 51L, 47L, 71L, 57L, 57L, 22L, 20L, 47L, 61L,
27L, 54L, 35L, 13L, 5L, 3L, 24L, 2L, 57L, 19L, 13L, 5L, 36L,
2L, 43L, 18L, 73L, 31L, 25L, 51L, 13L, 45L, 30L, 2L, 57L, 28L,
26L, 22L, 18L, 58L, 20L, 58L, 44L, 57L, 22L, 49L, 20L, 60L, 24L,
56L, 47L, 47L, 71L, 9L, 60L, 47L, 41L, 62L, 73L, 3L, 13L, 39L,
3L, 46L, 17L, 3L, 17L, 41L, 13L, 10L, 59L, 5L, 29L, 17L, 25L,
21L, 71L, 71L, 71L, 71L, 37L, 49L, 13L, 35L, 29L, 31L, 37L, 37L,
25L, 51L, 29L, 37L, 21L, 41L, 19L, 53L, 51L, 35L, 60L, 23L, 39L,
53L, 32L, 22L, 14L, 41L, 17L, 29L, 9L, 2L, 7L, 34L, 2L, 23L,
37L, 7L, 35L, 3L, 57L, 25L, 29L, 11L, 23L, 19L, 19L, 11L, 72L,
19L, 21L, 23L, 37L, 33L, 51L, 27L, 71L, 36L, 21L, 35L, 26L, 53L,
56L, 11L, 25L, 21L, 15L, 39L, 54L, 21L, 19L, 49L, 33L, 43L, 5L,
57L, 73L, 58L, 39L, 57L, 54L, 57L, 56L, 53L, 41L, 20L, 28L, 54L,
23L, 27L, 67L, 25L, 35L, 18L, 22L, 20L, 28L, 33L, 39L, 62L, 51L,
49L, 4L, 20L, 34L, 22L, 32L, 16L, 21L, 35L, 57L, 23L, 37L, 7L,
47L, 47L, 27L, 47L, 12L, 29L, 34L, 41L, 60L, 53L, 60L, 58L, 54L,
5L, 58L, 57L, 27L, 2L, 49L, 26L, 60L, 63L, 57L, 57L, 22L, 22L,
20L, 22L, 22L, 28L, 18L, 22L, 24L, 30L, 16L, 22L, 22L, 54L, 45L,
18L, 25L, 33L, 37L, 39L, 27L, 35L, 33L, 37L, 21L, 29L, 25L, 31L,
51L, 20L, 60L, 41L, 51L, 27L, 37L, 35L, 41L, 37L, 11L, 17L, 71L,
60L, 49L, 45L, 58L, 37L, 45L, 24L, 23L, 32L, 8L, 53L, 58L, 60L,
2L, 41L, 19L, 27L, 45L, 7L, 29L, 35L, 34L, 46L, 13L, 33L, 9L,
39L, 17L, 3L, 39L, 13L, 17L, 9L, 24L, 34L, 19L, 33L, 34L, 9L,
72L, 25L, 34L, 55L, 7L, 17L, 7L, 13L, 9L, 36L, 7L, 35L, 19L,
23L, 19L, 35L, 55L, 23L, 35L, 25L, 33L, 25L, 39L, 35L, 7L, 27L,
30L, 32L, 18L, 30L, 3L, 71L, 39L, 3L, 49L, 16L, 17L, 17L, 28L,
22L, 13L, 22L, 55L, 30L, 37L, 49L, 60L, 62L, 58L, 31L, 72L, 37L,
23L, 33L, 58L, 45L, 11L, 21L, 23L, 53L, 31L, 35L, 25L, 56L, 37L,
33L, 53L, 55L, 1L, 5L, 71L, 57L, 37L, 19L, 39L, 56L, 56L, 7L,
15L, 62L, 61L, 18L, 41L, 18L, 37L, 67L, 62L, 39L, 70L, 15L, 37L,
27L, 33L, 31L, 37L, 53L, 72L, 31L, 35L, 27L, 21L, 23L, 27L, 29L,
25L, 21L, 23L, 29L, 60L, 31L, 45L, 21L, 51L, 23L, 49L, 27L, 25L,
23L, 21L, 31L, 7L, 35L, 44L, 29L, 29L, 33L, 41L, 13L, 33L, 21L,
51L, 53L, 23L, 41L, 47L, 7L, 33L, 61L, 51L, 15L, 71L, 57L, 39L,
27L, 3L, 23L, 35L, 72L, 1L, 73L, 1L, 7L, 49L, 23L, 29L, 29L,
27L, 41L, 39L, 25L, 47L, 58L, 61L, 43L, 44L, 72L, 49L, 47L, 55L,
25L, 37L, 72L, 7L, 3L, 64L, 57L, 36L, 4L, 27L, 71L, 22L, 2L,
57L, 55L, 45L, 57L, 58L, 26L, 7L, 13L, 49L, 53L, 37L, 47L, 26L,
13L, 35L, 45L, 47L, 57L, 63L, 49L, 47L, 60L, 63L, 60L, 39L, 58L,
54L, 54L, 71L, 53L, 14L, 51L, 29L, 53L, 29L, 35L, 45L, 71L, 71L,
27L, 72L, 56L, 25L, 22L, 71L, 57L, 61L, 55L, 43L, 39L, 37L, 33L,
71L, 71L, 19L, 72L, 21L, 65L, 11L, 31L, 37L, 58L, 22L, 35L, 35L,
58L, 58L, 36L, 65L, 47L, 60L, 53L, 60L, 51L, 37L, 41L, 22L, 56L,
39L, 27L, 37L, 5L, 14L, 53L, 11L, 53L, 70L, 37L, 19L, 23L, 21L,
23L, 43L, 21L, 39L, 33L, 37L, 37L, 35L, 37L, 35L, 55L, 44L, 38L,
38L, 23L, 3L, 31L, 29L, 63L, 37L, 72L, 71L, 7L, 58L, 56L, 27L,
65L, 19L, 40L, 25L, 56L, 56L, 56L, 41L, 37L, 39L, 43L, 23L, 31L,
9L, 51L, 23L, 9L, 45L, 47L, 51L, 33L, 20L, 9L, 57L, 45L, 39L,
63L, 35L, 45L, 71L, 22L, 17L, 40L, 43L, 9L, 45L, 14L, 43L, 71L,
7L, 13L, 45L, 31L, 56L, 55L, 26L, 57L, 33L, 42L, 11L, 35L, 19L,
20L, 56L, 39L, 1L, 47L, 45L, 55L, 12L, 17L, 19L, 13L, 29L, 17L,
3L, 7L, 11L, 58L, 45L, 9L, 72L, 41L, 35L, 3L, 41L, 31L, 53L,
47L, 53L, 33L, 58L, 51L, 56L, 45L, 3L, 72L, 7L, 3L, 5L, 7L, 21L,
17L, 17L, 14L, 37L, 45L, 37L, 35L, 37L, 45L, 22L, 13L, 60L, 47L,
41L, 62L, 17L, 35L, 35L, 49L, 31L, 41L, 25L, 41L, 49L, 35L, 23L,
45L, 58L, 35L, 21L, 47L, 49L, 13L, 53L, 14L, 35L, 35L, 35L, 35L,
45L, 48L, 51L, 54L, 51L, 72L, 33L, 51L, 66L, 73L, 56L, 37L, 37L,
31L, 23L, 31L, 26L, 13L, 60L, 17L, 37L, 43L, 44L, 7L, 21L, 37L,
55L, 39L, 45L, 51L, 64L, 3L, 11L, 49L, 62L, 57L, 62L, 35L, 18L,
14L, 9L, 13L, 11L, 7L, 37L, 61L, 55L, 36L, 35L, 21L, 66L, 53L,
58L, 13L, 54L, 21L, 60L, 9L, 55L, 71L, 25L, 64L, 37L, 9L, 39L,
70L, 17L, 30L, 41L, 49L, 63L, 58L, 44L, 55L, 54L, 10L, 22L, 64L,
19L, 42L, 3L, 45L, 3L, 39L, 34L, 39L, 45L, 51L, 26L, 37L, 23L,
20L, 47L, 21L, 62L, 63L, 5L, 51L, 13L, 19L, 26L, 51L, 26L, 30L,
51L, 54L, 21L, 54L, 13L, 47L, 29L, 11L, 18L, 9L, 9L, 13L, 43L,
51L, 61L, 34L, 13L, 3L, 54L, 54L, 39L, 17L, 28L, 37L, 13L, 37L,
18L, 10L, 73L, 47L, 13L, 47L, 61L, 47L, 53L, 54L, 63L, 20L, 54L,
58L, 28L, 3L, 54L, 31L, 7L, 35L, 37L, 38L, 57L, 58L, 31L, 13L,
17L, 31L, 47L, 55L, 58L, 71L, 41L, 45L, 49L, 58L, 70L, 33L, 37L,
39L, 35L, 28L, 46L, 39L, 27L, 71L, 58L, 35L, 45L, 45L, 41L, 26L,
39L, 35L, 57L, 22L, 47L, 57L, 37L, 26L, 58L, 58L, 58L, 36L, 58L,
47L, 57L, 41L, 27L, 29L, 31L, 51L, 29L, 57L, 39L, 31L, 29L, 21L,
24L, 17L, 23L, 35L, 27L, 33L, 29L, 35L, 21L, 35L, 27L, 17L, 39L,
23L, 37L, 35L, 37L, 37L, 33L, 39L, 45L, 31L, 35L, 35L, 23L, 29L,
37L, 35L, 54L, 70L, 29L, 37L, 33L, 19L, 23L, 33L, 47L, 39L, 35L,
43L, 62L, 33L, 17L, 31L, 62L, 7L, 58L, 17L, 45L, 51L, 27L, 31L,
53L, 37L, 39L, 31L, 45L, 31L, 49L, 27L, 33L, 71L, 35L, 35L, 37L,
25L, 45L, 60L, 39L, 29L, 19L, 35L, 23L, 21L, 31L, 49L, 29L, 58L,
31L, 57L, 21L, 51L, 53L, 37L, 70L, 17L, 37L, 56L, 31L, 35L, 17L,
53L, 45L, 3L, 61L, 61L, 49L, 37L, 45L, 23L, 19L, 39L, 51L, 21L,
25L, 33L, 33L, 53L, 29L, 19L, 23L, 37L, 33L, 37L, 19L, 29L, 61L,
33L, 41L, 27L, 57L, 58L, 29L, 5L, 7L, 61L, 58L, 45L, 37L, 27L,
53L, 33L, 58L), .Label = c("0.80N", "0.80S", "10.45N", "10.45S",
"12.05N", "12.05S", "13.66N", "13.66S", "15.27N", "15.27S", "16.87N",
"16.87S", "18.48N", "18.48S", "2.41N", "2.41S", "20.09N", "20.09S",
"21.70N", "21.70S", "23.31N", "23.31S", "24.92N", "24.92S", "26.52N",
"26.52S", "28.13N", "28.13S", "29.74N", "29.74S", "31.35N", "31.35S",
"32.95N", "32.95S", "34.56N", "34.56S", "36.17N", "36.17S", "37.78N",
"37.78S", "39.38N", "39.38S", "4.02N", "4.02S", "40.99N", "40.99S",
"42.59N", "42.59S", "44.20N", "44.20S", "45.81N", "45.81S", "47.42N",
"49.03N", "5.63N", "5.63S", "50.63N", "52.24N", "52.24S", "53.84N",
"55.45N", "57.05N", "58.66N", "60.27N", "61.88N", "63.49N", "65.09N",
"68.31N", "69.92N", "7.23N", "7.23S", "8.84N", "8.84S"), class = "factor")
Here is a base R approach with chartr to change "N" to "+" and "S" to "-", and then some string processing with sub to change the "+" and "-" to be in front of the number
tmp <- chartr("NS", "+-", c("10N", "10N", "35S", "25S"))
as.numeric(sub("(\\d+)([-+])", "\\2\\1", tmp))
#[1] 10 10 -35 -25
not that efficient though, (and it assumes that always N/S will be present)
ifelse(grepl("N",df$x), as.numeric(gsub("N","",df$x)), -1*as.numeric(gsub("S","",df$x)))
# [1] 10 20 -35 -25
With gsub and grepl:
as.numeric(gsub('[NS]','',x)) * c(-1,1)[grepl('N',x) + 1]
This results in:
> as.numeric(gsub('[NS]','',x)) * c(-1,1)[grepl('N',x) + 1]
[1] 10 20 -35 -25
Even another option is to use the gsubfn package:
x <- c('10N','20N','35S','25S')
library(gsubfn)
sapply(gsubfn('N|S', list('N'='*1','S'='*-1'), x),
function(x) eval(parse(text = x)),
USE.NAMES = FALSE)
This results in:
> sapply(gsubfn('N|S', list('N'='*1','S'='*-1'), x),
+ function(x) eval(parse(text = x)),
+ USE.NAMES = FALSE)
[1] 10 20 -35 -25
Here is an option with parse_number() from readr package to get the numeric values from the column and endsWith (which is a more efficient version of grepl) to check the trailing letter and make a vector of 1 or -1 based on which letter it is with a little mathematics:
df$x <- with(df, readr::parse_number(x) * (-1) ^ endsWith(x, "S"))
df
# x
#1 10
#2 20
#3 -35
#4 -25

Resources