How to standardize the variables in R for regression analysis I have been looking at some tutorials and articles and couldn't get a scenario where two variables are in different scales and used in modeling.
So, firstly lets assume I have one metric of numeric type, other in percentages, and other in decimals. 


*

*If I want to use those variables in a regression model for
prediction then do I need to do some standardization before fitting a
model to the variables? If so how do we it in R or Python?

*Moreover, if I want to use these features in k-means
clustering, do I need to follow the same steps as mentioned above?

 A: For a linear regression you do not have to standardise. You just have to take care with the interpretation of the estimated coefficients.  Assume e.g. that you have two independent variables, $x_1$ in meter and $x_2$ in kilometer and you estimate the regression model $y = \beta_1 x_1 + \beta_2 x_2 + \beta_3 + \epsilon$, then there is no problem with the estimates $\hat{\beta}_i,i=1,2,3$. 
However you should not compare the coefficients in order to draw conclusions on the impact of the variables, so e.g. if $\hat{\beta}_1 > \hat{\beta}_2$ you can not say that $x_1$ has more impact on y than has $x_2$ because $x_1$ is in meter, while $x_2$ in km. 
If you want to standardise $x_1$ in R then you compute 'x1.standardised<-(x1-mean(x1))/sd(x1)'. 
Cluster analysis is different because it is based on a so-called (di-)simmilarity matrix: it clusters together points that are close to each other (=that are similar to each other).   The elements of this matrix represent the (inverse) distances between any two points in your sample. 
The distance measure used in cluster analysis does not have to be the Eucilidean distance but let's take it as an example.  Then if I measure the distance between two datapoints where the first coordinate is in meter and the second one in km, then the size of the difference between the coordinates of the two points will probably be larger for the first coordinate because it is expressed in meter.
The Euclidian distance is $\sqrt{\text{difference of the first coordinates}^2 + \text{difference of the second coordinates}^2}$
So the difference for first variable (in meter) will weight more than for the second one when we compute the Eucilidian distance, which means that the cluster analysis will give more importance to the first variable for clustering. 
A: for the standardizing part of your question, if you want to standardize a vector x in R, use the function 
     scale(x)

it is equivalent to 
    (x-mean(x))/sd(x)

