someone has probably answered this already but use
substr()
new variable<-substr(old.variable,1,1)
Simon.
- Original Message -
From: "kayj"
To:
Sent: Tuesday, February 10, 2009 6:50 PM
Subject: [R] How to split a character vector into 3 vectors
Hi ,
Does any one know how to spl
This splits them into a 3 column matrix:
> x <- c("ASK", "DGH", "ASG", "AUJ", "URT")
> library(gsubfn)
> z <- strapply(x, ".", simplify = rbind)
> z
[,1] [,2] [,3]
[1,] "A" "S" "K"
[2,] "D" "G" "H"
[3,] "A" "S" "G"
[4,] "A" "U" "J"
[5,] "U" "R" "T"
z[,1], z[,2] and z[,3] are your
kayj wrote:
> Hi ,
>
>
> Does any one know how to split a character vector , I have a vector X that
> looks like this and each row has 3 characters
>
> X
> ASK
> DGH
> ASG
> AUJ
> FRT
>
> I would like to split the vector into 3 vectors that look like this
>
> X1X2 X3
> A S K
>
Another option is:
read.table(textConnection(gsub("(\\w)", "\\1;", X)), sep = ";")
On Tue, Feb 10, 2009 at 4:50 PM, kayj wrote:
>
> Hi ,
>
>
> Does any one know how to split a character vector , I have a vector X that
> looks like this and each row has 3 characters
>
> X
> ASK
> DGH
> ASG
> AU
kayj wrote:
>
> Hi ,
>
>
> Does any one know how to split a character vector , I have a vector X that
> looks like this and each row has 3 characters
>
> X
> ASK
> DGH
> ASG
> AUJ
> FRT
>
> I would like to split the vector into 3 vectors that look like this
>
> X1X2 X3
> A S
See ?strsplit
Hope this is helpful,
Dan
Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204
> -Original Message-
> From: r-help-boun...@r-project.org
> [ma
Dear kayj,
Try this:
X<-c("ASK", "DGH", "ASG", "AUJ", "FRT")
res<-data.frame(do.call(rbind,strsplit(X,"")))
colnames(res)<-paste("X",1:ncol(res),sep="")
res
HTH,
Jorge
On Tue, Feb 10, 2009 at 1:50 PM, kayj wrote:
>
> Hi ,
>
>
> Does any one know how to split a character vector , I have a ve
7 matches
Mail list logo