Reputation: 9
I'am new to R. Hope You guys will help me out. I have imported a xlsx into R which is having already 3 col i have add extra col that it should reflect has 4th and 5th col
sample data
appid emi aid
12345 12 1
6789 15 2
101212 18 3
What i required is
appid emi aid 4thcol 5th col
12345 12 1 NA NA
6789 15 2 NA NA
101212 18 3 NA NA
Upvotes: -3
Views: 61
Reputation: 415
Based on your question here's a snippet:
> df <- data.frame(appid = rnorm(5,3,4), emi = rnorm(5,3,4), aid = rnorm(5,2,2))
> df[4:5] <- NA
Output:
> df
appid emi aid V4 V5
1 2.6589136 3.07117782 -1.806979 NA NA
2 4.0774645 -0.52254103 0.874758 NA NA
3 8.0565096 -0.61076733 -1.815436 NA NA
4 1.7483850 0.02000453 3.761556 NA NA
5 -0.3020456 3.64966057 4.607310 NA NA
Bonus, to rename the columns use `colnames'.
> colnames(df) <- c('w','X','y','Z', 'foo')
Upvotes: 0