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 120
#2 220
#3 320
#4 420
#5 520
#6 620
#7 720
#8 8
> 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 m
Why doesn't the code you posted work for you? "number" appears to be a
constant, so R will fill automatically the correct length.
(Note that calling your data frame df leads to confusion.)
> mydf <- data.frame(a=letters[1:5], b=runif(5))
> mydf
a b
1 a 0.52880425
2 b 0.02422788
3 c 0.56
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 d
4 matches
Mail list logo