r - How to create data.frame with defined number of rows? -


i want create data frame , know how many rows going have in advance. following code creates "empty" data frame:

result.data.frame <- data.frame(trusterid = integer(),                                 trusteeid = integer(),                                 rtt = integer(),                                 rtd = integer(),                                 rdt = integer(),                                 rdd = integer(),                                 trustvalue = factor(levels = c("1", "-1", "0"))) 

now how create data frame 10 rows , initial values: 0 integers , "0" factor?

just initialise data frame have already, ,

result.data.frame[1:10, ] <- 0 

the result of be

> str(result.data.frame) 'data.frame':   10 obs. of  7 variables:  $ trusterid : num  0 0 0 0 0 0 0 0 0 0  $ trusteeid : num  0 0 0 0 0 0 0 0 0 0  $ rtt       : num  0 0 0 0 0 0 0 0 0 0  $ rtd       : num  0 0 0 0 0 0 0 0 0 0  $ rdt       : num  0 0 0 0 0 0 0 0 0 0  $ rdd       : num  0 0 0 0 0 0 0 0 0 0  $ trustvalue: factor w/ 3 levels "1","-1","0": 3 3 3 3 3 3 3 3 3 3 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -