C'est ce que l'échantillon ressemble à:

# A tibble: 10 x 6
   trip_id bearing_1 bearing_2 bearing_3 bearing_4 bearing_5
     <int>     <dbl>     <dbl>     <dbl>     <dbl>     <dbl>
 1       1    -115.      26.0      28.5      29.0      44.2 
 2       2     -30.0   -104.     -151.      -79.7      86.3 
 3       3    -174.    -163.       28.9      28.4      33.4 
 4       4     109.      39.7     108.      -90.4     -96.4 
 5       5     164.     173.      172.     -155.     -151.  
 6       6      29.7     28.8      23.7      23.7      -5.72
 7       7    -152.    -152.     -140.      -87.8     -40.4 
 8   27393      36.8     -7.35    125.      125.       -6.25
 9   27394      38.2      8.01      8.01      8.01      8.01
10   27395     -66.6    -68.0     112.       86.0      -2.03
 my.df <- structure(list(trip_id = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 27393L,27394L, 27395L), bearing_1 = c(-114.841862569466, -29.9669766757283,-174.421109701553, 108.540950375186, 164.27892942256, 29.6758222025729,-151.952759961779, 36.7666184516413, 38.1774435895225, -66.5951081074832), bearing_2 = c(26.0208400403598, -103.956520193288, -162.685454728109,39.7241781616749, 172.795046874931, 28.7700915265229, -151.570082970024,-7.34765841903149, 8.00631142918635, -68.0088533670534), bearing_3 = c(28.5429778503258,-150.523766272678, 28.9060358290049, 107.799736478861, 171.649870654995,23.6732326703023, -139.805993936888, 124.715023127817, 8.00631142918635,111.724971807071), bearing_4 = c(29.0047950732172, -79.7472910710283,28.4442392651495, -90.3662617366973, -155.498976426312, 23.6732326703023,-87.7511498573422, 124.715023127817, 8.00631142918635, 85.9719398622447), bearing_5 = c(44.1517444467334, 86.2565875990879, 33.44598675342,-96.4423762052258, -150.883228746413, -5.72113572073526, -40.42741337969,-6.24787371298153, 8.00631142918635, -2.0336505253902)), row.names = c(NA,-10L), class = c("tbl_df", "tbl", "data.frame"))

Ainsi, bearing_1 à bearing_5 colonnes sont degré et je souhaite convertir ceci degree value en radians value. Existe-t-il des paquets et des fonctions de r qui peuvent calculer cela?

Mon résultat attendu devrait être comme ça,

# A tibble: 10 x 6
   trip_id radian_1         radian_2      radian_3        radian_4       radian_5
     <int>     <dbl>           <dbl>       <dbl>             <dbl>       <dbl>
 1       1    -2.007128     0.4537855     0.4974188      0.5061454      0.7714354
 2       2    -0.5235987   -1.815142     -2.635447      -1.391027       1.506219
r
2
Yasumin 4 mai 2021 à 19:07

2 réponses

my.df[,2:6] <- my.df[,2:6] * pi / 180
4
Peace Wang 4 mai 2021 à 16:15

Nous pouvons utiliser lapply

my.df[2:6] <- lapply(my.df[2:6], `*` pi/180)
3
akrun 4 mai 2021 à 16:16