I'm having trouble outputting the results of some R code into a data frame, for eventual export into CSV. I'm pretty new to R so I'm not sure what exactly the mistake is.
I have this input data set, called "ip_test":
ip ip_end country_name region_name city_name
702388992 702388994 US West LA
I'm then running this code:
g = 1
ip = as.numeric(ip_test[g,1])
df <- for(g in 1:as.numeric(nrow(ip_test)))
{ for(ip in as.numeric(ip_test[g,1]):as.numeric(ip_test[g,2]))
{ print(cbind(ip_address=ip,
country_name = paste(ip_test[g,3], collapse=" "),
region_name = paste(ip_test[g,4], collapse=" "),
city_name = paste(ip_test[g,5], collapse=" ")))
}
}
This is outputting these results:
ip_address country_name region_name city_name
[1,] "702388992" "US" "West" "LA"
ip_address country_name region_name city_name
[1,] "702388993" "US" "West" "LA"
ip_address country_name region_name city_name
[1,] "702388994" "US" "West" "LA"
The problem I'm having is that the data frame "df" is not getting populated with any data, it remains "NULL (empty)". I'm not sure exactly what the issue is since the outputted data is what I want. I looked into matrix vs data frame issues, rbind on the output, ldply, as.data.frame, R list to data frame. I'm getting the same issue of no output to the data frame on every bit of code. I tried the "melt" function in the reshape2 library per Multidimensional array into data frame, which created a data frame 1 column wide by 11 rows long with the numbers 0-10, and this error: "Error in names(object) <- nm : 'names' attribute 1 must be the same length as the vector [0]"
I'm thinking this is something basic with the output but I'm not able to figure out the issue. Any help would be very appreciated.