Reputation: 185
I want to initialize a dataframe that contains as rows: Date
, integer
, integer
, and decimal
.
Here is what I have so far:
df = data.frame(Date = date(), a = integer(0), b = integer(0), ratio = numeric(0.0), stringsAsFactors = FALSE)
This gives me the error:
Error in data.frame(Date = date(), a = integer(0), b = integer(0), ratio = numeric(0), :
arguments imply differing number of rows: 1, 0
When I remove the Date = date()
part, I no longer have this error.
I also tried:
df = data.frame(Date = date(0), a = integer(0), b = integer(0), ratio = numeric(0.0), stringsAsFactors = FALSE)
This gave me the error:
Error in date(0) : unused argument (0)
I have two questions:
Date
in a dataframe?decimal
in a dataframe? Is doing numeric(0.0)
how you do it?Upvotes: 0
Views: 624
Reputation: 887531
Try
df <- data.frame(Date = as.Date(character()), a = integer(),
b = integer(), ratio = numeric(), stringsAsFactors = FALSE)
str(df)
#'data.frame': 0 obs. of 4 variables:
#$ Date :Class 'Date' num(0)
#$ a : int
#$ b : int
#$ ratio: num
Upvotes: 1