How to remove variable from dataset

data.frame(table(df$trstun))
Var1 Freq
1 0 1510
2 1 734
3 2 1075
4 3 1352
5 4 1348
6 5 3134
7 6 1867
8 7 2168
9 8 1933
10 9 896
11 10 587
12 77 57
13 88 1306
14 99 93

After the 10th variable 11-14 are void results from the dataset. There were no survey answers with the options to pick 11,12,13, 14 as a preset answer on levels of trust in this research. Does anyone know how to remove this using the NA function. How would I tell R not to use 11, 12, 13 etc in data from tables I am trying to generate?

I think you are misreading the output. Your has the numbers 1 - 10 and 77, 88, and 99. The numbers at the left edge are row numbers of the data frame. Here is an example of a similar result.

#Invent data using values 11 through 20
DF <- data.frame(A = sample(11:20, 50, replace = TRUE)) 
head(DF) #Show  first 6 rows
#>    A
#> 1 12
#> 2 14
#> 3 20
#> 4 17
#> 5 18
#> 6 13
table(DF$A) #Counts of the values 11 - 20
#> 
#> 11 12 13 14 15 16 17 18 19 20 
#>  6  8  5  6  6  2  5  3  5  4
data.frame(table(DF$A)) #Data frame version of the table              
#>    Var1 Freq
#> 1    11    6
#> 2    12    8
#> 3    13    5
#> 4    14    6
#> 5    15    6
#> 6    16    2
#> 7    17    5
#> 8    18    3
#> 9    19    5
#> 10   20    4

Created on 2023-05-01 with reprex v2.0.2

Hi, yes i see what you mean. Do you know how to get rid of the 77,88,99 from my data frame or other tables because they are void results?

A handy way to remove rows from a data frame is to use the filter() function from the dplyr package. The following code will keep all rows where the value of the trstun column is <= 10. The result is stored in the new data frame df_clean.

library(dplyr)
df_clean <- filter(df, trstun <= 10)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.