Given two columns of type character in a dataframe of the form:
col1col2
31* 66
0 0*
102*66
71* 80
31 2*
66 31*
47 38*
How do I generate the following dataframe? Ie. col1 contains row item
with * and col2 contains row member without *
col1col2
I think several ways can do that.
my code is:
data.frame(t(apply(dat,1,function(x)as.numeric(sub(\\*,,x[sort(1:2,grep(\\*,x)==2)])
HTH
On 2/7/07, Dale Steele [EMAIL PROTECTED] wrote:
Given two columns of type character in a dataframe of the form:
col1col2
31* 66
0 0*
I'm sorry, I forgot my definition of dat.
dat in code of previous post is:
dat-data.frame(col1=c(31*,0,102*,71*,31,66,47),col2=c(66,0*,66,80,2*,31*,38*))
dat
col1 col2
1 31* 66
20 0*
3 102* 66
4 71* 80
5 31 2*
6 66 31*
7 47 38*
On 2/7/07, talepanda [EMAIL PROTECTED]
Try this:
DF - data.frame(
col1 = factor(c(31*, 0, 102*, 71*, 31, 66, 47)),
col2 = factor(c(66, 0*, 66, 80, 2*, 31*, 38))
)
replace(DF, TRUE, as.numeric(sub(*, , as.matrix(DF), fixed = TRUE)))
On 2/6/07, Dale Steele [EMAIL PROTECTED] wrote:
Given two columns of type character