How to make a table, which has 4 columns?

hi,

I want to make a table to further use it for a program where a program reads a value from that table.

amino acids molecular weights alpha carboxy alpha amino
1 a1 b1 c1
2 a2 b2 c2
3 a3 b3 c3
4 a4 b4 c4
5 a5 b5 c5
6 a6 b6 c6

where when I type 1 in my input it could read 1 as a1, b1 as well as c1.

I don't think your explanation of the problem you are trying to solve is clear enough to give you an answer as is.

For example does that table have 8 columns in it? The data you have presented has only 3 columns.

What do you mean that a 1 in the input would read a1 etc.

You should show the input and output are looking for.

You should include a reprex, even if the code doesn't work.

Is this what you are trying to do?

suppressPackageStartupMessages(library(tidyverse))
# make a table
tbl <- tribble(
~id,    ~x, ~y, ~z,
1L, "a1",  "b1", "c1",
2L, "a2", "b2", "c2"
)

tbl
#> # A tibble: 2 x 4
#>      id x     y     z    
#>   <int> <chr> <chr> <chr>
#> 1     1 a1    b1    c1   
#> 2     2 a2    b2    c2

# select just the row for id == 1L
filter(tbl, id == 1L)
#> # A tibble: 1 x 4
#>      id x     y     z    
#>   <int> <chr> <chr> <chr>
#> 1     1 a1    b1    c1

Created on 2018-03-06 by the reprex package (v0.2.0).

For information on reprex see https://www.jessemaegan.com/post/so-you-ve-been-asked-to-make-a-reprex/

For now the version of reprex in CRAN has some issues so you should install reprex directly from github.

Until CRAN catches up with the latest version install reprex with

devtools::install_github("tidyverse/reprex")

2 Likes