hi R community
i got this dataframe

when i try to convert to numeric i get:
sample1 <- as.numeric(sample1)
Error: 'list' object cannot be coerced to type 'double'
You need to specify the column you're making numeric.
mydf = data.frame(ID = c("123213213", "1232132132", "12321412321"))
as.numeric(mydf)
#> Error in eval(expr, envir, enclos): 'list' object cannot be coerced to type 'double'
as.numeric(mydf$ID)
#> [1] 123213213 1232132132 12321412321
class(mydf$ID)
#> [1] "character"
mydf$ID = as.numeric(mydf$ID)
class(mydf$ID)
#> [1] "numeric"
Created on 2021-12-06 by the reprex package (v2.0.1)
then it changes the values

and it is no longer a df
That's because you've overwritten your dataframe. You should have written:
sample1$ID <- as.numeric(sample1$ID)
so have this df:

wrote
![]()
got
![]()
dont understand it ![]()
That is very strange - is that dataframe called sample? Because it should just work:
sample = data.frame(ID = c("659175822", "595117221", "595117264", "595117708", "595119208"))
sample$ID
#> [1] "659175822" "595117221" "595117264" "595117708" "595119208"
as.numeric(sample$ID)
#> [1] 659175822 595117221 595117264 595117708 595119208
Created on 2021-12-06 by the reprex package (v2.0.1)
Could you paste the output of dput(sample)? Then I'll have access to the data we're talking about.
hmm giving me all the data (10k+)
okay say i have a df1 and job id in the first column (and name in second column) and i want to make a new dataframe with the first 10 rows from df1 into df2
then i want to add 1 row of data into df2
hope it makes sense ![]()
What about just dput(head(sample, 100))? That should give enough to play with.
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.