-1

I have a data frame A, with headers that describe qualities of an individual. Each of these qualities has 2 parts, the first of which has 3 possible answer and the second has two possible answers. Each column has a 0 if the individual does not possess that quality and a 1 if they do, in category of the quality (the groups of 3 and 2 answers) there is only ever a 1 value in one column. The first three columns of the frame contain the name of the individual and their coordinates.

I want to create data frames that contain the first three columns of all people who have a 1 in each column for qualities. ie. whether they answered 1, 2, or 3 for the first question about the quality. The frames will have the name of the header of the column.

At the moment I have

Aa <- qualities[qualities$Aa != 0,]
Ab <- qualities[qualities$Ab != 0,]
...
Ae <- qualities[qualities$Ae != 0,]
Ba <- qualities[qualities$Ba != 0,]
...
Ze <- qualities[qualities$Ze != 0,]

Obviously this is a stupid way of doing it. I need something that for all columns i, i={number of columns of qualities}, writes the function of the column to a new data frame. I think. I don't know how to do this, though as I can't seem to find a way of calling the column i and then writing it to the header of i as it's all text.

Thanks in advance!

Padster
  • 43
  • 1
  • 4
  • Please consider reading up on [ask] and how to produce a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Makes it easier for others to help you. – Heroka Nov 17 '15 at 13:21

1 Answers1

-1

you can put the dataframes in a list:

n <- names(qualities)[..] # [number of column "Aa" : number of column "Ze"]
dat.q <- function(q) qualities[qualities[,q]!=0,]
L <- lapply(n, dat.q)
names(L) <- n
jogo
  • 12,469
  • 11
  • 37
  • 42