Hi. I have a very specific question about maintaining decimals when scaling and unscaling. I am making a k-means cluster component analysis with GPS coordinates. I scaled the data before conducting the analysis:
scaled_data = as.matrix(scale(GPS))
Then I made the analysis, which resulted in four clusters. Now I want to export the members of each clusters to an txt/csv file, so I can continue my analysis. I used this code, which I copied of off the internet:
unscaled.cluster1 <- t(apply(GPS, 1,
+ function(r) r * attr(GPS, 'scaled:scale') +
+ attr(GPS, 'scaled:center')))
I then exported the members of cluster 1 to a txt file:
> sink(file = "cluster1unscaled.txt")
> unscaled.data[km$cluster==1,]
> sink(file = NULL)
The problem is that this process changed the number of decimals in the GPS coordinates, so now they are different than the original ones, which is making it impossible to continue my analysis. When I export the file to excel, it is not possible to change the number of decimals (when I try, I just get extra zeros) - this leads me to think that I need to do something in R to make sure that I get the original number of decimals back when unscaling.
Example:
Original X coordinate: 11.1373136079
New X coordinate after unscaling in R: 11.13731
I really hope someone can help, as I'm quite stuck here. Thanks!