Manage length of field values

0 votes

Hi All,

How to adjust the value lengths of a column in the data frame? My dataset has a column weight which has floating-point numbers. I want to have the same length of values for this field. Is it possible to manage the length without round off or truncate?

Oct 16, 2019 in Data Analytics by ch
• 3,450 points
612 views

1 answer to this question.

0 votes
Hi,

Use str_pad() function to format the length of field values (string type).

Syntax: str_pad(string,width, side = "left/right")

To use str_pad(), convert the numeric field to string and then back to numeric after padding.

Ex:

> c = c("1","10","3","4","50")
> c
[1] "1" "10" "3" "4" "50"
> str_pad(c,2,side = "right",pad = "0")
[1] "10" "10" "30" "40" "50"
answered Oct 23, 2019 by Cherukuri
• 33,030 points

Related Questions In Data Analytics

+1 vote
2 answers

Custom Function to replace missing values in a vector with the mean of values

Try this. lapply(a,function(x){ifelse(is.na(x),mean(a,na.rm = TRUE ...READ MORE

answered Aug 14, 2019 in Data Analytics by anonymous
1,941 views
+1 vote
2 answers

Finding number of missing values and removing those missing values from a data-frame

To find number of missing values for ...READ MORE

answered Aug 14, 2019 in Data Analytics by anonymous
1,103 views
0 votes
1 answer

Building Random Forest on a data-set comprising of missing(NA) values

You have two options, either impute the ...READ MORE

answered Apr 3, 2018 in Data Analytics by Bharani
• 4,660 points
1,389 views
+1 vote
1 answer

How to convert a list of vectors with various length into a Data.Frame?

We can easily use this command as.data.frame(lapply(d1, "length< ...READ MORE

answered Apr 4, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,669 views
0 votes
1 answer

By using dpylr package sum of multiple columns

Basically here we are making an equation ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
2,254 views
0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,925 views
0 votes
1 answer

In a dpylr pipline how to use sample and seq?

For avoiding rowwise(), I prefer to use ...READ MORE

answered Apr 6, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 9, 2020 by Gitika 1,184 views
0 votes
1 answer

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,344 views
0 votes
1 answer

Show count of unique values for each value in the field in dataframe

Hi, Use below r code. For one field, you ...READ MORE

answered Aug 21, 2019 in Data Analytics by anonymous
• 33,030 points
2,007 views
+1 vote
2 answers

How to count the number of elements with the values in a vector?

Use dplyr function group_by(). > n = as.data.frame(num) > ...READ MORE

answered Aug 21, 2019 in Data Analytics by anonymous
• 33,030 points
5,025 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP