Dear Bill,
Thanks a lot this is what I was looking for.
Emmanuel
On 2 November 2016 at 15:59, William Dunlap wrote:
> Give your new column a vector type - NULL cannot be extended beyond length
> 0. Also, the syntax df$col<-NULL means to remove 'col' from 'df'.
>
> > df <- data.frame(id=intege
> Now, how can I add a third column name to that empty df?
You could use functions that generate zero-length objects. Examples:
df$newv <- vector(mode="numeric") #logical by default, so <-vector() would give
you a zero-length logical
df$newi <- integer()
df$newf <- factor()
S Ellison
lto:r-help-boun...@r-project.org] On Behalf Of Emmanuel
> Levy
> Sent: Wednesday, November 2, 2016 2:48 PM
> To: r-h...@stat.math.ethz.ch
> Subject: [R] Adding a column to an **empty** data.frame
>
> Dear All,
>
> This sounds simple but can't figure out a good way to do it.
&
Dear All,
This sounds simple but can't figure out a good way to do it.
Let's say that I have an empty data frame "df":
## creates the df
df = data.frame( id=1, data=2)
## empties the df, perhaps there is a more elegant way to create an empty
df?
df = df[-c(1),]
> df
[1] id data
<0 rows> (or
Give your new column a vector type - NULL cannot be extended beyond length
0. Also, the syntax df$col<-NULL means to remove 'col' from 'df'.
> df <- data.frame(id=integer(0), data=numeric(0))
> df$new.col <- character(0)
> str(df)
'data.frame': 0 obs. of 3 variables:
$ id : int
$ data
5 matches
Mail list logo