Truncate numeric values without round off

0 votes
Hi Team,

I want to truncate numeric field values of fixed length without round off. How to do this?
Oct 23 in Data Analytics by anonymous
• 3,290 points
12 views

1 answer to this question.

0 votes
You can either use substring function or use str_pad to get the fixed length of value. For this, you need to convert number to string and vice Versa after truncating operation

> substring(number, ll, hl) where ll and hl are lower and higher index.

> str <- "hello this is my first program"
> str_trunc(str,15,side = "right",ellipsis = "")
[1] "hello this is m"
answered Oct 28 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
99 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
168 views
0 votes
4 answers

How to remove NA values with dplyr::filter()

Can we create a alist as below ...READ MORE

answered Aug 5 in Data Analytics by anonymous
9,186 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
115 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
159 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
86 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
104 views
0 votes
1 answer

How to modify column values using the same column without duplicating column?

Hi, Use mutate(). returns selected columns after modifying the ...READ MORE

answered Aug 30 in Data Analytics by anonymous
• 31,840 points
22 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
130 views