I'm trying to convert my data frame format using R. I want unique company name as it has multiple observations for each company. My data looks like
company name Values Year
A 1 2010
A 2 2011
B 4 2010
B 6 2012
C 8 2011
I want below format
company name first_value First_year second_values second_year
A 1 2010 2 2011
B 4 2010 6 2012
C 8 2011 NA NA
I have tried this code but it is not giving result what I am expecting
library(plyr)
extract.hashtags <- function(x) {
x <- subset(x,select=c(-Company.Name))
mat <- as.matrix(x)
dim(mat) <- c(1,length(mat))
as.data.frame(mat)
}
df1 = ddply(data, .(Company.Name), extract.hashtags )