r - Is there a way to guess the size of data.frame based on rows, columns and variable types -


i expecting generate lot of data , catch r. how can estimate size of data.frame ( , memory needed) number of rows, number of columns , variable types.

example.

if have 10000 rows , 150 columns out of 120 numeric, 20 strings , 10 factor level, size of data frame can expect. results change depending on data stored in columns ( in max(nchar(column)) )

> m <- matrix(1,nrow=1e5,ncol=150) > m <- as.data.frame(m) > object.size(m) 120009920 bytes > a=object.size(m)/(nrow(m)*ncol(m)) > 8.00066133333333 bytes > m[,1:150] <- sapply(m[,1:150],as.character) > b=object.size(m)/(nrow(m)*ncol(m)) > b 4.00098133333333 bytes > m[,1:150] <- sapply(m[,1:150],as.factor) > c=object.size(m)/(nrow(m)*ncol(m)) > c 4.00098133333333 bytes > m <- matrix("ajayajay",nrow=1e5,ncol=150) >  > m <- as.data.frame(m) > object.size(m) 60047120 bytes > d=object.size(m)/(nrow(m)*ncol(m)) > d 4.00314133333333 bytes 

you can simulate object , compute estimation of memory being used store r object using object.size:

m <- matrix(1,nrow=1e5,ncol=150) m <- as.data.frame(m) m[,1:20] <- sapply(m[,1:20],as.character) m[,29:30] <- sapply(m[,29:30],as.factor) object.size(m) 120017224 bytes print(object.size(m),units="gb") 0.1 gb 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -