revalue and lapply

Hallo R studio community,
my issue:

data[,85:99 ] <- lapply(data[ ,c(85:99)], revalue(data[ ,c(85:99)], c("0"= FALSE, "1" = TRUE)))

and I get this error

Error in revalue(data[, c(85:99)], c(0 = FALSE, 1 = TRUE)) :
x is not a factor or a character vector.

any help? thanks!

#> No documentation for 'revalue' in specified packages and libraries:
#> you could try '??revalue'

Created on 2020-06-05 by the reprex package (v0.3.0)
It appears that revalue is a function of package plyr so probably that is the function you try to use.

Please make a reprex of your problem where you replace data by a small tibble, data.frame or matrix (or whatever you use) with the same contents as your columns 85 till 99.



  i_no_0 i_no_1 i_no_10 i_no_11 i_no_12 i_no_13 i_no_14 i_no_2 i_no_3 i_no_4 i_no_5 i_no_6 i_no_7 i_no_8
1      0      0       0       0       0       0       0      1      0      1      0      0      0      0
2      0      0       0       0       0       0       1      0      0      0      0      0      0      0
3      0      0       0       0       0       0       0      0      0      0      0      0      0      0
4      0      0    <NA>    <NA>    <NA>    <NA>    <NA>      0      1      0   <NA>   <NA>   <NA>   <NA>
5      0      0       0    <NA>    <NA>    <NA>    <NA>      0      0      0      0      0      0      0
6      0      0    <NA>    <NA>    <NA>    <NA>    <NA>      0      0      0      0      0      0   <NA>

Maybe I was too subtle.
I meant I will not look into your problem if you don't make a reprex : so much to do and so little time.

But I am sure someone else will be willing to help out.

thank you anyway, I am very beginner in R!

I think it is important that we understand what is your actual problem:
apparently you have a matrix (not a data.frame) with numbers (and NA) (so not factors) and you want to replace the number 0 by FALSE and the number 1 by TRUE and NA by ?? .
According the documentation the plyr::revalue function works only on characters or factors.
BTW the function plyr::mapvalues is mentioned that also handles numbers.

My suggestion: create a small input x (x being your data source) exactly as your data source.
So if there are characters you specify characters, numbers if numbers etc.
And show us how you do this (not showing only the print result).
And check the reference about reprex I mentioned: it is really useful.

Also tell us what you want to achieve apart from changing zeros and ones:
if you are starting with R then maybe want to learn to use tidyverse packages (e.g. dplyr has nice data.frame capabilities) or do just want to avoid it and use the basic R functions?

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