new variable - null

Hello
I am a beginner and I'd like to ask your help.
I created a new variable in my table (tableau). When I apply data.frame command I can get this new variable. Each value is there too. But when I apply tableau$newvariable, I get NULL. How may I fix it?
Thank you.

The $ operator will return a NULL if a column does not exist. For example,

DF <- data.frame(A = 1:4)
DF$B
NULL

Please show the actual code to make the data frame and the code that returns the NULL.

1 Like

thank you for your answer. But i think the column exists (Poids_2 is the new variable):

Poids_2 <- tableau_cours3$Poids
Poids_2
[1] 82 88 84 94 99 108 93 79 94 90 88 84 88 97 98 100 86 95 107 86 86 84 108 96 89
data.frame(tableau_cours3, Poids_2)
quantile(tableau_cours3$Poids_2)
0% 25% 50% 75% 100%
NA NA NA NA NA
tableau_cours3, Poids_2
Error: unexpected ',' in "tableau_cours3,"
tableau_cours3$Poids_2
NULL

It looks like you need to redefine tableau_cours3 first and then try taking the quantile.

Poids_2 <- tableau_cours3$Poids
tableau_cours3 = data.frame(tableau_cours3, Poids_2)
quantile(tableau_cours3$Poids_2)

This topic was automatically closed 42 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.