Hello,
You don't need rep(), R will fill the entire column with the number.
See the example below.
dat <- data.frame(x = 1:10)
dat$newnumber <- 20
dat
# x newnumber
#1 1 20
#2 2 20
#3 3 20
#4 4 20
#5 5 20
#6 6 20
#7 7 20
#8 8 20
#9 9 20
#10 10 20
So your code works: df$newcolumn <- number
Hope this helps,
Rui Barradas
On 5/10/2018 2:04 PM, Marcelo Mariano Silva wrote:
Hi,
I am a begginer in R programming.
I am traying to create a a column in my data frame filled down with a
number.
df$newcolumn <- number
How can I do it? I am considering use rep() but in this case it is
necessary know the number of rows in each data base that I have and I would
like to do it in a faster ( and more elegant) way.
TKs
[[alternative HTML version deleted]]
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.