# duplicate

> For the complete documentation index, see [llms.txt](https://kotlin.github.io/dataframe/llms.txt).

Repeats rows or whole dataframes: [duplicateRows](#duplicaterows) repeats rows inside a [DataFrame](dataframe.html), [duplicate](#duplicate-on-a-datarow) on a [DataRow](datarow.html) makes a [DataFrame](dataframe.html) out of copies of the row, and [duplicate](#duplicate-on-a-dataframe) on a [DataFrame](dataframe.html) makes a [FrameColumn](datacolumn.html#framecolumn) out of copies of the whole dataframe.

API reference: [duplicate](https://kotlin.github.io/dataframe/api-docs/core/org.jetbrains.kotlinx.dataframe.api/duplicate.html)

Related operations: [Append / duplicate rows](appendduplicate.html)

The number of copies `n` counts the original too, so `n = 1` gives one copy. `n` must be greater than 0. For `n = 0` or a negative `n`, every `duplicate` and `duplicateRows` call throws an `IllegalArgumentException`.

Every example on this page uses the same [DataFrame](dataframe.html):

```KOTLIN
df
```

[Embedded content](./resources/duplicateDf.html)

## duplicateRows

Returns a [DataFrame](dataframe.html) where every row is repeated `n` times. The copies of a row come right after it, so the order of the rows stays the same. The examples use the `df` shown at the top of this page.

```TEXT
duplicateRows(n): DataFrame
duplicateRows(n) { rowCondition }: DataFrame
```

```KOTLIN
df.duplicateRows(3)
```

[Embedded content](./resources/duplicateRows.html)

With a [row condition](datarow.html#row-conditions), only the rows that match it are repeated. The other rows appear once, as before:

Properties:

```KOTLIN
df.duplicateRows(3) { age > 18 }
```

Strings:

```KOTLIN
df.duplicateRows(3) { "age"<Int>() > 18 }
```

[Embedded content](./resources/duplicateRowsWhere.html)

Values in column groups and frame columns are repeated together with their rows. The column names and types stay the same.

Don't confuse `duplicateRows` with [distinct](distinct.html), which removes repeated rows.

## duplicate on a DataRow

Returns a [DataFrame](dataframe.html) with `n` rows, each of them a copy of the row. The example uses the `df` shown at the top of this page.

```TEXT
DataRow.duplicate(n): DataFrame
```

```KOTLIN
df[1].duplicate(3)
```

[Embedded content](./resources/duplicateRow.html)

The result has the same columns as the dataframe the row comes from, column groups and frame columns included. The type of each column follows the value in the row: a nullable column whose value in the row is not `null` becomes non-nullable in the result. Here `name` is `String?` in `people`, and `String` in the copies of the first row:

```KOTLIN
val people = dataFrameOf(
    "name" to listOf("Alice", null),
    "age" to listOf(15, 20),
)
people[0].duplicate(2).schema()
```

Output:

```TEXT
name: String
age: Int
```

## duplicate on a DataFrame

Returns a [FrameColumn](datacolumn.html#framecolumn) with `n` cells, each holding the whole dataframe. The column has an empty name. The example uses the `df` shown at the top of this page.

```TEXT
DataFrame.duplicate(n): FrameColumn
```

```KOTLIN
df.duplicate(3)
```

[Embedded content](./resources/duplicateDataFrame.html)

A dataframe gives a column without a name the name `untitled`, so the table above shows it this way.

To get one [DataFrame](dataframe.html) with all rows of `df`, followed by all rows of `df` again, [concat](concat.html) the copies:

```KOTLIN
df.duplicate(2).concat()
```

[Embedded content](./resources/duplicateDataFrameConcat.html)

See also: [append](append.html), [concat](concat.html), [distinct](distinct.html).

