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 in Data Analytics by ch
• 3,290 points
20 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 by Cherukuri
• 31,840 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 in Data Analytics by anonymous
101 views
+1 vote
2 answers
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 2, 2018 in Data Analytics by Bharani
• 4,550 points
171 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
131 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
116 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
161 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
87 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
105 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 in Data Analytics by anonymous
• 31,840 points
54 views
0 votes
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 in Data Analytics by anonymous
• 31,840 points
131 views