Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- df = read.table('data.txt', header = T)
- df$x
- df$y
- df = df[-1,]
- df$x = NULL
- # create a data.frame with 10 rows
- > x = rnorm(10)
- > y = runif(10)
- > df = data.frame( x, y )
- # write it to a file
- > write.table( df, 'test.txt', row.names = F, quote = F )
- # read a data.frame from a file:
- > read.table( df, 'test.txt', header = T )
- > df$x
- [1] -0.95343778 -0.63098637 -1.30646529 1.38906143 0.51703237 -0.02246754
- [7] 0.20583548 0.21530721 0.69087460 2.30610998
- > df$y
- [1] 0.66658148 0.15355851 0.60098886 0.14284576 0.20408723 0.58271061
- [7] 0.05170994 0.83627336 0.76713317 0.95052671
- > df$x = x
- > df
- y x
- 1 0.66658148 -0.95343778
- 2 0.15355851 -0.63098637
- 3 0.60098886 -1.30646529
- 4 0.14284576 1.38906143
- 5 0.20408723 0.51703237
- 6 0.58271061 -0.02246754
- 7 0.05170994 0.20583548
- 8 0.83627336 0.21530721
- 9 0.76713317 0.69087460
- 10 0.95052671 2.30610998
- > df[-1,]
- y x
- 2 0.15355851 -0.63098637
- 3 0.60098886 -1.30646529
- 4 0.14284576 1.38906143
- 5 0.20408723 0.51703237
- 6 0.58271061 -0.02246754
- 7 0.05170994 0.20583548
- 8 0.83627336 0.21530721
- 9 0.76713317 0.69087460
- 10 0.95052671 2.30610998
- > df$x = NULL
- > df
- y
- 1 0.66658148
- 2 0.15355851
- 3 0.60098886
- 4 0.14284576
- 5 0.20408723
- 6 0.58271061
- 7 0.05170994
- 8 0.83627336
- 9 0.76713317
- 10 0.95052671
- dat <- dat[-1, ]
- > dat <- data.frame(A = 1:3, B = 1:3)
- > dat[-1, ]
- A B
- 2 2 2
- 3 3 3
- > dat2 <- dat[-1, ]
- > dat2
- A B
- 2 2 2
- 3 3 3
- #remove rows that have long length and "0" value for vector E
- >> setNew<-set[!(set$length=="long" & set$E==0),]
- dat <- dat[2:nrow(dat), ]
Add Comment
Please, Sign In to add comment