Could anyone answer this?
I have a dataframe (thousands of rows) with a particular column name Name
and I want to modify the dataframe based on the column Name
e.g. I have a sample dataframe
df1<-data.frame(Id=c(1,2,3,4,5,6,7,8,9,10),
Name=c('Plant_A','Plant_A','Plant_A','Plant_A','Plant_B','Plant_B','Plant_B','Plant_C','Plant_C','Plant_C'),
Value=c(100,100,100,100,55,55,55,90,90,90),
stringsAsFactors=FALSE)
Now, according to the columnName
the new columns namely Availability
and Status
should be added/populate with the values shown in the dataframe df2
. The first value of the row with Yes
and 0
and rest of the values for the same Name
should be No
and empty `` and so on.
df2<-data.frame(Id=c(1,2,3,4,5,6,7,8,9,10),
Name=c('Plant_A','Plant_A','Plant_A','Plant_A','Plant_B','Plant_B','Plant_B','Plant_C','Plant_C','Plant_C'),
Value=c(100,100,100,100,55,55,55,90,90,90),
Availability=c('Yes','No','No','No','Yes','No','No','Yes','No','No'),
Status =c(0,'','','',0,'','',0,'',''),
stringsAsFactors=FALSE)
I can add only one type of the value like,
df1$Availability<-'Yes'
df1$Status<-0
But don't understand how to populate df1
in order to get df2
. Can anyone help me? Thank you.