r

Remove some factor-interaction terms from estimation

。_饼干妹妹 提交于 2021-02-10 07:13:20
问题 I'd like to remove certain factor interactions from an estimation. Here's an example with generated data from an imaginated labour market (I uploaded it here: http://pastebin.com/raw.php?i=EcMEVqUC) s <- source("http://pastebin.com/raw.php?i=EcMEVqUC")$value lm(income ~ age + cit * prof, data=s) In this example economy, foreigners are not allowed to work in the public sector, therefore citforeign:profofficial is NA . Therefore I would like to exclude the interaction term of citforeign

Remove some factor-interaction terms from estimation

旧街凉风 提交于 2021-02-10 07:10:12
问题 I'd like to remove certain factor interactions from an estimation. Here's an example with generated data from an imaginated labour market (I uploaded it here: http://pastebin.com/raw.php?i=EcMEVqUC) s <- source("http://pastebin.com/raw.php?i=EcMEVqUC")$value lm(income ~ age + cit * prof, data=s) In this example economy, foreigners are not allowed to work in the public sector, therefore citforeign:profofficial is NA . Therefore I would like to exclude the interaction term of citforeign

Remove some factor-interaction terms from estimation

做~自己de王妃 提交于 2021-02-10 07:09:31
问题 I'd like to remove certain factor interactions from an estimation. Here's an example with generated data from an imaginated labour market (I uploaded it here: http://pastebin.com/raw.php?i=EcMEVqUC) s <- source("http://pastebin.com/raw.php?i=EcMEVqUC")$value lm(income ~ age + cit * prof, data=s) In this example economy, foreigners are not allowed to work in the public sector, therefore citforeign:profofficial is NA . Therefore I would like to exclude the interaction term of citforeign

use of pipe operator “%>%” using :: in R

£可爱£侵袭症+ 提交于 2021-02-10 07:06:30
问题 I am building an R package and I am using intensively the pipe operator %>%. I am wandering how to call it from purrr package using :: operator. I have tried purrr::%>% but get an error. I appreciate any guide on this. P.D: should I call the pipe operator from magrittr rather than purrr? 回答1: Your best approach is to import it from magrittr and re-export it if you want your users to be able to access it. Using it internally to your package only, this may work: `%>%` <- purrr::`%>%` check:

How do I remove a selection made using Shiny and mapedit by clicking again on the feature?

独自空忆成欢 提交于 2021-02-10 06:57:43
问题 Using Shiny, leaflet, and mapedit packages I can generate a graph with multiple series using the code below. Intuitively I would like to click on a selected map icon a second time and the associated data is removed from the graph. Essentially the click event can be toggled on or off. Does anyone have any suggestions? # devtools::install_github("r-spatial/sf") # devtools::install_github("r-spatial/mapview@develop") # devtools::install_github("bhaskarvk/leaflet.extras") # devtools::install

All values between min and max

一笑奈何 提交于 2021-02-10 06:52:50
问题 Suppose I know the min and max id, what I need is to have all ids between the min and max ones. Suppose id<-c(1:20) now min=1 and max=20 which function in R show the all values between these two numbers? 回答1: You can use sets algebra: id <- c(1:20) setdiff(id, range(id)) #[1] 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Also you can do: id[!(id %in% range(id))] or: id[!(id %in% c(max(id), min(id)))] 来源: https://stackoverflow.com/questions/43746935/all-values-between-min-and-max

Linear regression with only previous values in moving window

百般思念 提交于 2021-02-10 06:49:49
问题 I have a huge dataset and would like to perform a rolling linear regression over a window of 60. However, I want that only the 60 previous values are considered for the linear regression. My Dataframe DF consists of following Columns: Date Company Y X1 X2 01.01.2015 Mill 0.13 -1 -3 01.02.2015 Mill 0.16 1 5 01.03.2015 Mill 0.83 3 4 01.04.2015 Mill -0.83 23 4 01.01.1988 Hall 0.23 1 3 01.02.1988 Hall 0.24 23 2 01.03.1988 Hall 0.78 19 -9 01.04.1988 Hall 0.73 4 12 01.05.1988 Hall 0.72 5 12 01.11

Logical operators in if-else in R

霸气de小男生 提交于 2021-02-10 06:48:39
问题 I have the following table (5 columns and 3 rows) called mat : AC CA RES 1 0 2 2 1 3 0 0 0 1 The operation being performed is mat[1]/mat[1]+mat[2] I am testing for the following : 1) If both columns of a row are zero, the result should be NA. 2) If only one column of a row is zero and the other has a non-zero number, proceed with calculation. (Even if the numerator is 0, that's okay) I am currently using this if-else structure within a for-loop going row-wise: if(mat[b,1]>=0|mat[b,2]>=0){mat

How to plot polylines in multiple colors in R?

旧城冷巷雨未停 提交于 2021-02-10 06:42:07
问题 I'm working on a custom route planner in R at the moment. I'm using the output of the Google Maps Directions API. I want to show the route on a map between two places. Everything is going great so far. The only problem is that I don't know how to give the route multiple colors based on Speed at the moment. I searched the internet for a few days and I couldn't find something that fits my goal. That's why I made this post. Then I visualized it in Leafet with te following code: #install.packages

Lubridate as_date and. as_datetime differences in behavior

僤鯓⒐⒋嵵緔 提交于 2021-02-10 06:41:33
问题 I have a vector of numerics representing the number of milliseconds since January 1, 1970. I would like to convert these into a date time object using lubridate . A sample of data is below: raw_times <- c(1139689917479, 1139667123031, 1140364113915, 1140364951003, 1139643685434, 1139677091970, 1139691963511, 1140339448413, 1140368308429, 1139686613641, 1139666081813, 1140351488730, 1140346617958, 1141933663183, 1141933207579, 1140360125149, 1140351845108, 1140365079103, 1141933549825,