Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

How to add a column in a table using R script?

I would like to add an extra column in an existing table and I want that column to be filled with the following text "YTD".

 

output <- as.data.frame(dataset, stringsAsFactors = FALSE, row.names=NULL)
output$F <- "YTD"

 I get following error message:

 

DataSource.Error: ADO.NET: R script error.
Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
  duplicate 'row.names' are not allowed
Calls: read.csv -> read.table
Execution halted

Details:
    DataSourceKind=R
    DataSourcePath=R
    Message=R script error.
Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
  duplicate 'row.names' are not allowed
Calls: read.csv -> read.table
Execution halted

    ErrorCode=-2147467259
    ExceptionType=Microsoft.PowerBI.Scripting.R.Exceptions.RScriptRuntimeException

Any help will be appreciated

2 REPLIES 2
Anonymous
Not applicable

Hi.

I have a similar problem. I want to add a new column in a table using Power Bi but I don't know how!

The script code is: 

 

 

# new variable

dataset$new <- 0

 

f=nrow(dataset)

 

for (i in 2:f) {

 

if( dataset$num[i-1] == dataset$num[i] ) {
dataset$new[i-1] = dataset$start [i-1] - dataset$end[i] - 1


}


else { dataset$new[i-1] = "NO"
}
}

 

 

How can I insert this code?

Could help me, please?

 

Many thanks,

regards.

 

v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

For the error "duplicate 'row.names' are not allowed ", you can refer to the similar cases:

https://stackoverflow.com/questions/8854046/duplicate-row-names-are-not-allowed-error ,

https://stackoverflow.com/questions/15285089/r-duplicate-row-names-are-not-allowed.

 

Best Regards,

Amy

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Users online (2,965)