I am having difficultly with my R code. I am trying to create a new dataframe, based on a dataframe I already have, where each duplicate value is individually multiplied by 1000 and added by 1 in order. For example, the values in my dataframe range from 3869014 to 4524673 and there are multiple values of each number (up to 100). Ex: [3869014, 3869014, 3869014, 3869014, 3869014, 3869014, 3869014, 3869014, 3869015, 3869015, 3869015, 3869015, 3869016, 3869016, 3869016, 3869016, etc...]. What I want is: [3869014001, 3869014002, 3869014003, 3869014004, 3869014005, 3869014006, 3869014007, 3869014008, 3869015001, 3869015002, 3869015003, 3869015004, 3869016001, 3869016002, 3869016003, 3869016004, etc...]
I tried the following code, but it multiplies each number by 1000 and adds one regardless of duplicates. It also only adds one, rather than adding a count (ex: 1,2,3,4,etc...). So the output is [3869014001, 3869014001, 3869014001, 3869014001, etc... which is not what I want. I am somewhat new to looping in R dataframes. Thanks for the help.
setwd("F:/TimData/SPAM/Ethiopia")
#clear all variables
rm(list=ls())
#install packages
install.packages(c("spatstat","maptools","lattice","sp","RColorBrewer","splancs","maps", "plyr"))
install.packages(c("rgdal","raster","R.utils","spsurvey", "xlsx", "rJava", "foreign"),dep=TRUE)
#load libraries
library(spatstat); library(maptools); library(lattice); library(sp);
library(RColorBrewer); library(splancs); library(maps)
library(rgdal); library(raster); library(R.utils); library(spsurvey); library(foreign);
library(rJava)
library(xlsx)
library(plyr)
#creating a custom 1km spatial grid
kmgrid = readGDAL("EthiopiaBuffer1km.tif")
#convert raster to data frame
kmgridx= as.data.frame(kmgrid, row.names=NULL, optional=FALSE, xy=FALSE, na.rm=TRUE)
#specify column containing raster values
x=kmgridx$band1
#setting counter for while statement, based on actual min/max values of raster #grid
start = 3869014
finish = 4525673
#setting loop to multiply each duplicate by 1000 and add one, doesn't work
while (start < finish) {
if (start) {
for (i in 1:length(x)) {y=(x*1000)+1}
start=start +1 }
}