utils_num_str: Utilities for handling with numbers and strings

Description Usage Arguments Author(s) Examples

Description

[Stable]

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

Arguments

.data

A data frame

...

The argument depends on the function used.

  • For round_cols() ... are the variables to round. If no variable is informed, all the numeric variables from data are used.

  • For all_lower_case(), all_upper_case(), all_title_case(), stract_number(), stract_string(), remove_strings(), and tidy_strings() ... are the variables to apply the function. If no variable is informed, the function will be applied to all non-numeric variables in .data.

pattern

A string to be matched. Regular Expression Syntax is also allowed.

replacement

A string for replacement.

ignore_case

If FALSE (default), the pattern matching is case sensitive and if TRUE, case is ignored during matching.

digits

The number of significant figures.

sep

A character string to separate the terms. Defaults to "_".

Author(s)

Tiago Olivoto tiagoolivoto@gmail.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
library(metan)

################ Rounding numbers ###############
# All numeric columns
round_cols(data_ge2, digits = 1)

# Round specific columns
round_cols(data_ge2, EP, digits = 1)

########### Extract or replace numbers ##########
# Extract numbers
extract_number(data_ge, GEN)
# Replace numbers
replace_number(data_ge, GEN)
replace_number(data_ge,
               GEN,
               pattern = 1,
               replacement = "_one")

########## Extract, replace or remove strings ##########
# Extract strings
extract_string(data_ge, GEN)

# Replace strings
replace_string(data_ge, GEN)
replace_string(data_ge,
               GEN,
               pattern = "G",
               replacement = "GENOTYPE_")

# Remove strings
remove_strings(data_ge)
remove_strings(data_ge, ENV)


############ Find text in numeric sequences ###########
mixed_text <- data.frame(data_ge)
mixed_text[2, 4] <- "2..503"
mixed_text[3, 4] <- "3.2o75"
find_text_in_num(mixed_text, GY)

############# upper, lower and title cases ############
gen_text <- c("This is the first string.", "this is the second one")
all_lower_case(gen_text)
all_upper_case(gen_text)
all_title_case(gen_text)
first_upper_case(gen_text)

# A whole data frame
all_lower_case(data_ge)


############### Tidy up messy text string ##############
messy_env <- c("ENV 1", "Env   1", "Env1", "env1", "Env.1", "Env_1")
tidy_strings(messy_env)

messy_gen <- c("GEN1", "gen 2", "Gen.3", "gen-4", "Gen_5", "GEN_6")
tidy_strings(messy_gen)

messy_int <- c("EnvGen", "Env_Gen", "env gen", "Env Gen", "ENV.GEN", "ENV_GEN")
tidy_strings(messy_int)

library(tibble)
# Or a whole data frame
df <- tibble(Env = messy_env,
             gen = messy_gen,
             Env_GEN = interaction(Env, gen),
             y = rnorm(6, 300, 10))
df
tidy_strings(df)

metan documentation built on Nov. 10, 2021, 9:11 a.m.