通过ID用非NA值替换NA

时间:2019-09-11 07:29:22

标签: r

df中,我想用每个ID的非NA值替换NA值

id<-c(1,1,1,1,2,2,2)
price<-c(NA,20,NA,NA,NA,NA,5)
df<-data.frame(id,price)

 id    price
  1       NA
  1       20
  1       NA
  1       NA
  2       NA
  2       NA
  2        5

理想情况下,输出应如下所示:

id      price
  1       20
  1       20
  1       20
  1       20
  2        5
  2        5
  2        5

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

使用public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; response.setHeader("Access-Control-Allow-Origin","*"); response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Methods", "POST, GET,DELETE, PUT"); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With,Origin, remember-me,empID,Authorization,password ,username,Access-Control-Request-Headers,Access-Control-Request-Method"); chain.doFilter(req, res); }

data.table