add column with name in R
1
0
Entering edit mode
sat • 0
@ccbf0270
Last seen 3 months ago
italy
 I want to add a column with name "category" to my data, how can i do that?
 input:
 col1 col2 col3 col4 col5 
 1     20   +    4     6 
 2     24   -    6     7
....

output:

 col1 col2 col3 col4 col5  col6
 1     20   +    4     6   category
 2     24   -    6     7   category
....
name R column • 530 views
ADD COMMENT
2
Entering edit mode
helucro ▴ 70
@crowellh-11823
Last seen 9 months ago
University of Zurich, Switzerland

Assuming your data is in a data.frame called df:

  • df$col6 <- "category" or
  • df[["col6"]] <- "category" or
  • data.frame(df, col6 = "category")
  • ...
ADD COMMENT

Login before adding your answer.

Traffic: 505 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6