Guest User

Untitled

a guest
Jul 16th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. df = read.table('data.txt', header = T)
  2.  
  3. df$x
  4. df$y
  5.  
  6. df = df[-1,]
  7.  
  8. df$x = NULL
  9.  
  10. # create a data.frame with 10 rows
  11. > x = rnorm(10)
  12. > y = runif(10)
  13. > df = data.frame( x, y )
  14.  
  15. # write it to a file
  16. > write.table( df, 'test.txt', row.names = F, quote = F )
  17.  
  18. # read a data.frame from a file:
  19. > read.table( df, 'test.txt', header = T )
  20.  
  21. > df$x
  22. [1] -0.95343778 -0.63098637 -1.30646529 1.38906143 0.51703237 -0.02246754
  23. [7] 0.20583548 0.21530721 0.69087460 2.30610998
  24. > df$y
  25. [1] 0.66658148 0.15355851 0.60098886 0.14284576 0.20408723 0.58271061
  26. [7] 0.05170994 0.83627336 0.76713317 0.95052671
  27.  
  28. > df$x = x
  29. > df
  30. y x
  31. 1 0.66658148 -0.95343778
  32. 2 0.15355851 -0.63098637
  33. 3 0.60098886 -1.30646529
  34. 4 0.14284576 1.38906143
  35. 5 0.20408723 0.51703237
  36. 6 0.58271061 -0.02246754
  37. 7 0.05170994 0.20583548
  38. 8 0.83627336 0.21530721
  39. 9 0.76713317 0.69087460
  40. 10 0.95052671 2.30610998
  41.  
  42. > df[-1,]
  43. y x
  44. 2 0.15355851 -0.63098637
  45. 3 0.60098886 -1.30646529
  46. 4 0.14284576 1.38906143
  47. 5 0.20408723 0.51703237
  48. 6 0.58271061 -0.02246754
  49. 7 0.05170994 0.20583548
  50. 8 0.83627336 0.21530721
  51. 9 0.76713317 0.69087460
  52. 10 0.95052671 2.30610998
  53.  
  54. > df$x = NULL
  55. > df
  56. y
  57. 1 0.66658148
  58. 2 0.15355851
  59. 3 0.60098886
  60. 4 0.14284576
  61. 5 0.20408723
  62. 6 0.58271061
  63. 7 0.05170994
  64. 8 0.83627336
  65. 9 0.76713317
  66. 10 0.95052671
  67.  
  68. dat <- dat[-1, ]
  69.  
  70. > dat <- data.frame(A = 1:3, B = 1:3)
  71. > dat[-1, ]
  72. A B
  73. 2 2 2
  74. 3 3 3
  75. > dat2 <- dat[-1, ]
  76. > dat2
  77. A B
  78. 2 2 2
  79. 3 3 3
  80.  
  81. #remove rows that have long length and "0" value for vector E
  82.  
  83. >> setNew<-set[!(set$length=="long" & set$E==0),]
  84.  
  85. dat <- dat[2:nrow(dat), ]
Add Comment
Please, Sign In to add comment