Advertisement
Guest User

R test: export to DBF

a guest
Aug 29th, 2011
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.76 KB | None | 0 0
  1. ##
  2. # Script to test the exporting to dbf of tables with many columns in R.
  3. ##
  4.  
  5. library(foreign)
  6.  
  7.  
  8. ###
  9. NUM=1000
  10.  
  11. v = c(1:NUM)
  12. test = matrix(v, ncol=length(v))
  13.  
  14. name_cols = c()
  15. for (i in 1:NUM) {
  16.     name_cols = c(name_cols, paste("A_",i,sep=""))
  17. }
  18. colnames(test) <- name_cols
  19.  
  20. write.dbf(test, "/tmp/test1000.dbf")
  21.  
  22.  
  23. ### NOW WITH 8000 columns
  24.  
  25. NUM=8000
  26.  
  27. v = c(1:NUM)
  28. test = matrix(v, ncol=length(v))
  29.  
  30. name_cols = c()
  31. for (i in 1:NUM) {
  32.     name_cols = c(name_cols, paste("A_",i,sep=""))
  33. }
  34. colnames(test) <- name_cols
  35.  
  36. write.dbf(test, "/tmp/test8000.dbf")
  37.  
  38. ########
  39. ## Check results
  40.  
  41. d1000 = read.dbf('/tmp/test1000.dbf')
  42. d8000 = read.dbf('/tmp/test8000.dbf')
  43.  
  44. length(d1000)
  45. ## Returns --> [1] 1000
  46.  
  47. length(d8000)
  48. ## Returns --> [1] 1856
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement