![]() Statusfy hide icon professional#"Master's, professional school, or doctoral degree", Ses_data_reduced$EDUCD_MOM_reclass <- ifelse(ses_data_reduced$EDUCD_MOM = 65 & ses_data_reduced$EDUCD_MOM= 81 & ses_data_reduced$EDUCD_MOM= 101 & ses_data_reduced$EDUCD_MOM= 114 & ses_data_reduced$EDUCD_MOM<= 116, "Master's, professional school, or doctoral degree", Ses_data_reduced$EDUCD_MOM_reclass<- NULL #create empty field. “Master’s, professional school, or doctoral degree”) Ordered_levels_ipums = c(“High school diploma or the equivalent, such as GED”, “Some college but no degree”, “Associate degree in college”, “Bachelor’s degree”, Statusfy hide icon code#Here’s my code so you can understand what I am working with: I want the value to stay as NA if it’s true and to report the observed value if it is false. I want to use the is.na and define what I want it to do if it finds an NA value. I’m trying to reclass values for a dataframe and I’m populating values in an already existing table with new values in a specific column with the ifelse function. Points(x, y, # Overlay NA values with numbers Text(x_NA, y_NA, cex = 2, # Add NA values to plot Pch_numb <- as.character( # Specify plotted numbers Par(mar = c(0, 0, 0, 0)) # Remove space around plot Par(bg = "#1b98e0") # Set background color ![]() X <- runif(N) # Uniformly distributed variables Points (x, y, # Overlay NA values with numbers Text (x_NA, y_NA, cex = 2, # Add NA values to plot "NA", col = "red" ) Par (mar = c ( 0, 0, 0, 0 ) ) # Remove space around plot Par (bg = "#1b98e0" ) # Set background color X <- runif (N ) # Uniformly distributed variables According to our previous data generation, it should be approximately 20% in x_num, 30% in x_fac, and 5% in x_cha. Is.na_blank_fac <- as.factor(is.na_blank_fac) # Recode back to factorĬombined with the R function sum, we can count the amount of NAs in our columns. Is.na_blank_fac <- "" # Class character to blank Is.na_blank_fac <- as.character(is.na_blank_fac) # Convert temporarily to character Is.na_blank_fac <- data$x_fac # Duplicate factor column Is.na_blank_cha <- "" # Class character to blank Is.na_blank_cha <- data$x_cha # Duplicate character column na_blank_fac <- "" # Class character to blank is. na_blank_fac ) # Convert temporarily to character is. na_blank_fac <- data$x_fac # Duplicate factor column is. na_blank_cha <- "" # Class character to blank is. na_blank_cha <- data$x_cha # Duplicate character column is. Let’s apply the is.na function to our whole data set: Table 1: Example Data for the is.na R Function (First 6 Rows) This is how the first six lines of our data look like: Our data consists of three columns, each of them with a different class: numeric, factor, and character. X_cha <- NA # 5% missingsĭata <- ame(x_num, x_fac, x_cha, # Create data frame X_cha <- sample(letters, N, replace = TRUE) # Character X_fac <- as.factor(round(runif(N, 0, 3))) # Factor frame (x_num, x_fac, x_cha, # Create data frame X_cha <- sample (letters, N, replace = TRUE ) # Character ![]() factor (round (runif (N, 0, 3 ) ) ) # Factor X_num <- round (rnorm (N, 0, 5 ) ) # Numeric ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |