R: create new variable, the new value are not correct -


I create a new variable to "summarize" 4 variables "HS_A / B / C / D" in "Data 1" HS "I am using:

  HS & lt; - Enclose (5, Length (Data 1)) (Data 1) HS [HS_A == 2 & amp; HSB == 2 & amp; HSAC == 2 & amp; HSID == 2] & lt; - 0 HS [HS_A == 1 & amp; HSB == 2 & amp; HSAC == 2 & amp; HSID == 2] & lt; - 1 HS [HSB == 1 & amp; HS_A == 2 & amp; HSAC == 2 & amp; HSID == 2] & lt; - 2 HS [HSAC == 1 & amp; HS_A == 2 & amp; HSB == 2 & amp; HSD == 2] & lt; - 3 HS [HSID == 1 & amp; HS_A == 2 & amp; HSB == 2 & amp; HSAC == 2] & lt; - 4 HS1 & lt; -data.frame (HS_A, HSBH, HSAC, HSAD, HS)  

I want all other values ​​in HS 5 If they are not 0/1/2/3/4, then I just use rep 5. The problem is that, HS is NA , while I think they should be 5 .

Any NA code> Data 1 , and I using rows with HS using NA ( which has been examined (!! rowsums (is.na (hs)) ). # [1] 1545 1646 1687 1744 1784 1817 and they " 1212 NA " " 1112 NA " " 1112 NA " 1112 NA " " 1112 NA " " 1112 NA ".

Does anyone help explain this Is there a way to create variables or a way to solve?

How to do new variables in for loop?

I think that there is NA

Basic The value in the taxate is data1 . Therefore, if any line has NA value then any condition specified will be FALSE and 5 . The condition may also be, where the combination between columns is wrong for situations, which are also given as 5 ., SP = '')) Lvls & lt; - c ('2222', '1222', '2122', '2212', '2221') Indx [! Indx% in% lvls] & lt; 6 Data 1 $ HS & Lt; - as.numeric (Factors (Indx, Level = C (LVLS, 6)) - 1

Here is a glimpse of Data 1

 Lupli (split (data1, data1 $ hs), head, 2) # $ `0` #hs_a hsbh hsn hsdh hs # 1029 2 2 2 2 0 0 # 1064 2 2 2 2 0 0 # $ `1` # HS_A HSBH HSN HSD HS # 164 1 2 2 2 1 # 661 1 2 2 2 # # $ `2` # HS_A HSBH HSN HSAD HS # 46 2 1 2 2 2 # 211 2 1 2 2 2 # $ `3` # HS_A HSBH HSN HSAD HS # 34 9 2 2 1 2 3 # 42 9 2 2 1 2 3 # $` 4` # HS_A HSBH HSAN HSD HA # 152 2 2 2 1 4 # 307 2 2 2 1 4 # $ 5 `HS_A HSBS HSCA HS_DHS # 1 NA 2 3 1 5 # 2 1 3 NA 2 5  

Data
  set.seed (345) data 1 & lt; - As Data.frame (Matrix (Sample (C (NA, 1: 3), 4 * 1500, Replacement = TRUE), ncol = 4, dimnames = list (NULL, paste ("HS", letter [1: 4] ], Sep = "_"))))  


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -