Skip to content
Back to formatted view

Raw Message

Message-ID: <4ED7C7BA.7040408@gmail.com>
Date: 2011-12-01T18:30:18Z
From: saschaview at gmail.com
Subject: transform data.frame holding answers --> data.frame holding logicals

Hello

Hello

I have a data frame, x, holding 5 persons answering the question which 
cars they have used:

# the data frame
x <- as.data.frame(
   matrix(
     c('BMW', '', '',
       'Mercedes', 'VW', '',
       'Skoda', 'VW', 'BMW',
       '', '', '',
       'VW', 'Skoda', ''
     ),
     ncol=3,
     dimnames=list(
       NULL,
       paste( 'v', 1:3, sep='' )
     )
   )
)

How do I transform this data frame to a data frame stating whether they 
have used the presented car:

    BMW  Mercedes  VW  Skoda
1  T    F         F   F
2  F    T         T   F
3  T    F         T   T
4  F    F         F   F
5  F    F         T   T

My idea was to first find all levels by:

v <- unique(unlist(lapply(x, levels)))

But then I am stuck.

Thanks for help, *S*

-- 
Sascha Vieweg, saschaview at gmail.com