Here is my data
summary(RecordsWithIssues)
ID OTHERSTATE OTHERCOUNTRY
Length:373 Length:373 Length:373
Class :character Class :character Class :character
Mode :character Mode :character Mode :character
> head(RecordsWithIssues)
# A tibble: 6 × 3
ID OTHERSTATE OTHERCOUNTRY
<chr> <chr> <chr>
1 0034000001uhro2AAA MO <NA>
2 0034000001uhyOsAAI <NA> reseller
3 0034000001uhyPJAAY <NA> AECbytes
4 0034000001uhyPZAAY <NA> Friend
5 0034000001uhyPeAAI <NA> client
6 0034000001uhyPnAAI <NA> good energies
I do the following
RecordsWithIssues[,3]=tolower(RecordsWithIssues[,3])
RecordsWithIssues[1,3]
# A tibble: 1 × 1
OTHERCOUNTRY
<chr>
1 c(na, "reseller", "aecbytes", "friend", "client", "good energies", "boss", "friend", "linkedin", "aecbytes", "
>
As you can see data frame now has a vector instead of single text value. How can I simply convert the string without getting the text
To convert an uppercase string to lowercase in R, use the tolower() method. It takes a string as an argument and returns the lowercase version. The tolower() method changes the case of a string to the lower.
To convert all columns of the data frame into the character we use apply() function with as. character parameter. The lapply() function applies the given function to the provided data frame.
Method 1: using colnames() method colnames() method in R is used to rename and replace the column names of the data frame in R. The columns of the data frame can be renamed by specifying the new column names as a vector. The new name replaces the corresponding old name of the column in the data frame.
require(tidyverse)
RecordsWithIssues %>% mutate(OTHERCOUNTRY = tolower(OTHERCOUNTRY))
The data.table way:
require(data.table)
setDT(RecordsWithIssues)
RecordsWithIssues[ , OTHERCOUNTRY := tolower(OTHERCOUNTRY) ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With