Re: [R] Adding a column to an **empty** data.frame

2016-11-02 Thread Emmanuel Levy
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 <-

Re: [R] Adding a column to an **empty** data.frame

2016-11-02 Thread S Ellison
> 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

Re: [R] Adding a column to an **empty** data.frame

2016-11-02 Thread PIKAL Petr
[mailto: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. > &

[R] Adding a column to an **empty** data.frame

2016-11-02 Thread Emmanuel Levy
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

Re: [R] Adding a column to an **empty** data.frame

2016-11-02 Thread William Dunlap via R-help
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