I'd like to create data frames dynamically and assign custom names to it.
I have a master data set like this:
ID grp val1 val2
1 a 32 9
1 b 21 31
1 c 43 76
2 a 23 67
2 b 5 45
2 c 65 76
3 a 43 34
3 b 43 7
3 c 12 87
4 a 43 35
4 b 65 87
4 c 21 55
I'd like to create data frames like
data1:
ID grp val1 val2
1 a 32 9
1 b 21 31
1 c 43 76
data2:
ID grp val1 val2
2 a 23 67
2 b 5 45
2 c 65 76
and so on...
I have tried some things like:
myID<-1:4
df <- paste('data',myID, sep ='')
ll <- sapply(df, function(x)
{
data.frame ()
df<-masterData[which(masterData$ID==myID),]
})
Another try without desired results:
sapply(myID,function(x) df<-as.data.frame(masterData[which(masterData$ID==myID,]))
I guess subset will not do it for multiple values:
myframes<-list(subset(masterData,masterData$ID==myID))