I have a data frame with a column full of 13-digit numbers. But there is a mistake there, there had to be a decimal point before the last 3 digits (e.g., the number 1582305791901 should have been 1582305791.901).
So I thought I could easily solve this problem by simply dividing the entire column by 1000. But this does not preserve the decimal points, instead I get 1582305791. How can I solve this? (P.S. The column is of type "numeric", not "integer".)
Thank you!
try running this option first
options(digits = 15)
check if your number is stored as integer with typeof and class, then as.numeric(x)/1000
Related
I have a data frame in R that I want to analyse. I want to know how many specific numbers are in a data frame column. for example, I want to know the frequency of number 0.9998558 by using
sum(deviation_multiple_regression_3cell_types_all_spots_all_intersection_genes_exclude_50_10dec_rowSums_not_0_for_moran_scaled[,3]== 0.9998558)
However, it seems that the decimal shown is not the actual one (it must be 0.9998558xxxxx) since the result I got from using the above command is 0 (the correct one should be 3468). How can I access that number without knowing the exact decimal numbers so that I get the correct answer? Please see the screenshot below.
The code below gives the number of occurrences in the column.
x <- 0.9998558
length(which(df$a==x))
If you are looking for numbers stating with 0.9998558, I think you can do it in two different ways: working with data as numeric or as character.
Let x be your variable:
Data as character
This way counts exactly what you are looking for
sum(substr(as.character(x),1,9)=="0.9998558")
Data as numeric
This will include all the values with a difference with the reference value lower than 1e-7; this may include values not starting exactly with 0.9998558
sum(abs(x-0.9998558)<1e-7)
You can also "truncate" the numbers in your vector and compare them with the number you want. Here, we write 10^7 because 7 is the number of decimals you want to compare.
sum(trunc(x*10^7)/10^7)==0.9998558)
I am trying to log values for a meter at one minute intervals. In lieu of entering the full value each time, I want to be able to enter just the numbers that are different: as opposed to entering the difference of the values or the entire number.
I have a rather cumbersome formula for doing this and it's good for new digits greater than zero but less than ten, after that, it just adds the number to the total.
If I could just enter the new digits, that would be ideal, whether they be .65, 1.25, 35.95, or 501.69 etc.
Thank you!
I attacked it from the other direction and it now does what I want with a few less backflips.
It still removes the decimal so a trailing zero doesn't get lost in LEN().
Whatever the number of digits that are in the new number, it replaces that number of digits out of the original number with zeroes.
It adds the new number to the modified number.
It divides by 100 to get the decimal back.
I have no doubt there is a much more elegant way of doing this.
Thank you!
In my data set there is a field that is currently a character field and I need to convert it to a numeric one. the problem is not only are there '%' signs hard coded in the data but there are decimal points in there as well and places after the decimal points is not consistent. AKA...
42.01%
8.1%
22%
.05%
I substringed off the % sign but is there a way to just cut the decimal point off and everything after it so then I can just cast it as an integer?
thanks all
Cut % then convert to double. Then apply ceiling function.
What I had to do was put leading 0's on the front of the element because cognos was not reading the entries that started with decimal places. then I had to substring the % off and trim and then cast as a number.
I need an R-code to delete certain percentage of numbers in a vector and replace the deleted numbers with another number....
e.g
consider this random number,
x=rnorm(100,1,3)
I want to delete 25% of the generated numbers and replace the deleted numbers by deleted number+29
Please, I need somebody to help me with this. Thanks.
For example :
x[seq_len(length(x)*0.25)] <- 29
This will replace in front of x. You can randomize the result using sample(x).
Another option is to use x as a base for generation :
c(sample(x,size = length(x)*0.75) ,rep(29, length(x)*0.25))
I am Using RDLC Expression for rounding of my data to 4 decimals. but if i use 'Round' function it will show zeros after decimal point if the data has no decimal values.
Ex: If my value is 1 it shows 1.0000.
How to remove zeros?
My Expression: =Round(CDec(Fields!ExchangeRate.Value),4)
I need number without decimal point as whole number, if it has decimal values then it should display with decimal values.
Thanks in Advance.
=Format(CDec(Fields!ExchangeRate.Value),"#.####")
Above Expression Works fine. Thank You.
Simply try this...it works for me.
you can use the Format property of the textbox as
1- right click the textbox
2- click number
3- select Number from the category
4- set Decimal Places to 0
hope it will help you
regards