[R] split dataframe to several dataframes in R

Zilefac Elvis zilefacelvis at yahoo.com
Tue Feb 17 04:53:57 CET 2015


Hi All,I have a dataframe called 'means' as shown below:iris1.csv <- iris
iris2.csv <- iris
names <- c("iris1.csv", "iris2.csv")
dat <- mget(names)
lst4 <- lapply(dat, function(x) apply(x[,-5], 2, mean))

# Build the new data frame
means <- as.data.frame(do.call(rbind, lst4))
means$source <- names(lst4)
means
#           Sepal.Length Sepal.Width Petal.Length Petal.Width       isv    source
# iris1.csv     5.843333    3.057333        3.758    1.199333 0.3333333 iris1.csv
# iris2.csv     5.843333    3.057333        3.758    1.199333 0.3333333 iris2.csvQUESTION: How can I split 'means' such that there are two files (dataframes) on my workspace:datframe 1#           Sepal.Length Sepal.Width Petal.Length Petal.Width       isv    
# iris1.csv     5.843333    3.057333        3.758    1.199333 0.3333333dataframe 2:#           Sepal.Length Sepal.Width Petal.Length Petal.Width       isv# iris2.csv     5.843333    3.057333        3.758    1.199333 0.3333333
Many thanks,Asong.
	[[alternative HTML version deleted]]



More information about the R-help mailing list