# NOT RUN {
library(metan)
################# Adding columns #################
# Variables x and y .after last column
data_ge %>%
add_cols(x = 10,
y = 30)
# Variables x and y .before the variable GEN
data_ge %>%
add_cols(x = 10,
y = 30,
.before = GEN)
# Creating a new variable based on the existing ones.
data_ge %>%
add_cols(GY2 = GY^2,
GY2_HM = GY2 + HM,
.after = GY)
############### Reordering columns ###############
reorder_cols(data_ge2, NKR, .before = ENV)
reorder_cols(data_ge2, where(is.factor), .after = last_col())
######## Selecting and removing columns ##########
select_cols(data_ge2, GEN, REP)
remove_cols(data_ge2, GEN, REP)
########## Selecting and removing rows ###########
select_rows(data_ge2, 2:3)
remove_rows(data_ge2, 2:3)
########### Concatenating columns ################
concatenate(data_ge, ENV, GEN, REP)
concatenate(data_ge, ENV, GEN, REP, drop = TRUE)
# Combine with add_cols() and replace_string()
data_ge2 %>%
add_cols(ENV_GEN = concatenate(., ENV, GEN, pull = TRUE),
.after = GEN) %>%
replace_string(ENV_GEN,
pattern = "H",
replacement = "HYB_")
# Use prefixes and suffixes
concatenate(data_ge2, REP, prefix = "REP", new_var = REP)
# Use prefixes and suffixes (the ear traits EH, EP, EL, and ED)
add_prefix(data_ge2, PH, EH, EP, EL, prefix = "EAR")
add_suffix(data_ge2, PH, EH, EP, EL, suffix = "EAR", sep = ".")
# Use prefixes and suffixes (colnames)
concatenate(data_ge2, REP, prefix = "REP", new_var = REP)
########### formating column names ###############
# Creating data with messy column names
df <- head(data_ge, 3)
colnames(df) <- c("Env", "gen", "Rep", "GY", "hm")
df
colnames_to_lower(df)
colnames_to_upper(df)
colnames_to_title(df)
################### Adding rows ##################
data_ge %>%
add_rows(GY = 10.3,
HM = 100.11,
.after = 1)
########## checking if a column exists ###########
column_exists(data_g, "GEN")
####### get the levels, level combinations and size of levels ########
get_levels(data_g, GEN)
get_levels_comb(data_ge, ENV, GEN)
get_level_size(data_g, GEN)
############## all possible pairs ################
all_pairs(data_g, GEN)
########## select numeric variables only #########
select_numeric_cols(data_g)
select_non_numeric_cols(data_g)
# }
Run the code above in your browser using DataLab