-2

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 
RHertel
  • 23,412
  • 5
  • 38
  • 64
Arun P
  • 11
  • 3

1 Answers1

0

Welcome to R and Stack Overflow. Please read how to ask a question

Meanwhile, 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')
snair.stack
  • 405
  • 4
  • 13