Need to convert duplicate column elements to a unique element in R I need to convert the table A to table B. How can I do that using R?
TABLE A
Y 10
Y 12
Y 18 
X 22 
X 12
Z 11
Z 15

TABLE B
X 22 12
Y 10 12 18
Z 11 15 

 A: Here is the possible solution with taking a clarification in comment in mind, but still I think that the question is invalid as it stands.
##This gives the table A with both columns in character, which we will use
df<-rbind(c("Y",10),c("Y",12),c("Y",18),c("X",22), c("X",12), c("Z",11), c("Z",15))
> df
     [,1] [,2]
[1,] "Y"  "10"
[2,] "Y"  "12"
[3,] "Y"  "18"
[4,] "X"  "22"
[5,] "X"  "12"
[6,] "Z"  "11"
[7,] "Z"  "15"

##break the table into the list
l <-tapply(df[,2],df[,1],function(l)l)

##calculate the maximum length of the list element
n <- max(sapply(l,length))

##pad the elements of the list with empty strings
tbB<-t(sapply(l,function(x){res <- rep("",n);res[1:length(x)]<-x;res}))
> tbB
  [,1] [,2] [,3]
X "22" "12" ""  
Y "10" "12" "18"
Z "11" "15" ""  

##Comma separated file 
write.table(tbB,file="tableB.csv",quote=FALSE,col.names=FALSE,sep=",")


##Tab delimited 
write.table(tbB,file="tableB.txt",quote=FALSE,col.names=FALSE,sep="\t")

If we read the table A from the file, then df is a data.frame with first column a factor and second column numeric (this is a default R behaviour). To apply the code above it is necessary to transform the columns to character: 
df <- sapply(df,as.character) 

A: Similar to what @mpiktas proposed, but using aggregate
# Construct the data frame
let <- c("Y", "Y", "Y", "X", "X", "Z", "Z")
num <- c(10, 12, 18, 22, 12, 11, 15)

df <- data.frame(let, num)

# Aggregate data by the first column.
# Do not apply any transformation to the data (use the identity function)
ag <- aggregate(df$num, FUN=identity, by=list(let))
# Find the line with maximum number of elements
maxlen <- max(sapply(ag$x, length)))
# Transform the list to a matrix
res <- t(sapply(ag$x, function(x){c(x, rep(NA, maxlen-length(x)))}))
row.names(res) <- ag[,1]

Outputs:
1> res
  [,1] [,2] [,3]
X   22   12   NA
Y   10   12   18
Z   11   15   NA

