samedi 28 février 2015

Creating multiple data frames


Vote count:

0




I am attempting to create two separated data frames using the apply family however I run into trouble when attempting to create them as shown below.



X <- c(3,4,3,2,3,4,5,6,7,7,6,5,4,3,3,5,3,6,3,5,6,3,6,3,4,5,5,4,3,4,5,3,5,5,4)
Y <- c(3,2,1,3,4,2,1,2,3,5,4,3,2,1,1,3,4,5,6,7,6,5,4,3,2,3,4,3,4,2,4,3,NA,NA,NA)

mydata<-data.frame(X,Y)

L <- seq(1:length(mydata))
n <- function(x) length(na.omit(mydata[,x]))
n <- lapply(L,n)

# sequence each (Variable time)
x <- function(x) seq(1:n[[x]])
x <- lapply(L,x)
y <- function(x) na.omit(mydata[,x])
y <- lapply(L,y)

# create multiple data frames
Data <- function (x) data.frame(y[[x]], x[[x]])
Data <- lapply(L,Data)
# Error en x[[x]] : subíndice fuera de los límites

# what am I doing wrong I can not figure out how to do it using mapply
# However works if I do (when L is 1 and 2 referring to the x and x, for example

data.frame(y[[2]], x[[2]])


asked 17 secs ago







Creating multiple data frames

Aucun commentaire:

Enregistrer un commentaire