Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a suffix (or prefix) elements of an existing list?

Tags:

r

Let's say I have an existing list called myList.

myList <- list(list1=c("item1", "item2"), list2=c("item3", "item4"))

myList thus contains:

$list1
[1] "item1" "item2"

$list2
[1] "item3" "item4"

I want to append .t0 to each element of list1 and list2 within myList so I end up with:

$list1
[1] "item1.t0" "item2.t0"

$list2
[1] "item3.t0" "item4.t0"

I do not want to go back to the list(list1=c("item1", "item2"), list2=c("item3", "item4")) step and add .t0 there. I want to manipulate myList to add .t0.

like image 262
Eric Green Avatar asked Dec 17 '13 19:12

Eric Green


People also ask

How do you use prefixes and suffixes in word?

When the Prefix and Suffix window opens, add one or the other, or both, in the Prefix and Suffix boxes. Check the box for Apply to Entire List and click “OK.” As an example, we’ll use “Step” as the prefix and a greater than symbol (>) instead of a period as the suffix.

How to add a suffix to a group of cells in Excel?

After adding the suffix (PHD.) to the first cell, you can quickly add this common Suffix to all the other Cells by dragging the formula down to all the Cells in column C (See image below). Another way to Add Prefix or Suffix to a group of Cells in Excel is to make use of the “Concatenate” function as available in Microsoft Excel.

What is an example of a suffix?

Suffix: is an affix that is placed at the end of an entity in order to alter its meaning. For example in the word “ strongest ” est is a suffix and strong is an original entity.

What is preprefix?

Prefix: is an affix that is placed at the beginning of an entity in order to alter its meaning. For example in the word “ rematch ” re is a prefix and match is an original entity.


1 Answers

Use lapply and paste0

> lapply(myList, paste0, ".t0")
$list1
[1] "item1.t0" "item2.t0"

$list2
[1] "item3.t0" "item4.t0"
like image 88
Jilber Urbina Avatar answered Sep 20 '22 01:09

Jilber Urbina