How do I change every element in a vector to my reference class?How to access the last value in a vector?Test if a vector contains a given elementCounting the number of elements with the values of x in a vectorHow to find common elements from multiple vectors?Extract every nth element of a vectorIs there an R function for finding the index of an element in a vector?Is there a way to declare public and private methods for S4 Reference Classes?How to remove last n characters from every element in the R vectorChanging every element in vector or list by the same numberHow to implement a dispose pattern into a reference class in R?

Count the occurrence of each unique word in the file

Are the IPv6 address space and IPv4 address space completely disjoint?

why `nmap 192.168.1.97` returns less services than `nmap 127.0.0.1`?

What if a revenant (monster) gains fire resistance?

Is it possible to have a strip of cold climate in the middle of a planet?

2.8 Why are collections grayed out? How can I open them?

What should you do if you miss a job interview (deliberately)?

The screen of my macbook suddenly broken down how can I do to recover

Loading commands from file

On a tidally locked planet, would time be quantized?

Why Shazam when there is already Superman?

How much character growth crosses the line into breaking the character

How can Trident be so inexpensive? Will it orbit Triton or just do a (slow) flyby?

Yosemite Fire Rings - What to Expect?

Is it safe to use olive oil to clean the ear wax?

Create all possible words using a set or letters

Removing files under particular conditions (number of files, file age)

Can I sign legal documents with a smiley face?

What should you do when eye contact makes your subordinate uncomfortable?

Aragorn's "guise" in the Orthanc Stone

Why did the Mercure fail?

How to bake one texture for one mesh with multiple textures blender 2.8

How can "mimic phobia" be cured or prevented?

What is this called? Old film camera viewer?



How do I change every element in a vector to my reference class?


How to access the last value in a vector?Test if a vector contains a given elementCounting the number of elements with the values of x in a vectorHow to find common elements from multiple vectors?Extract every nth element of a vectorIs there an R function for finding the index of an element in a vector?Is there a way to declare public and private methods for S4 Reference Classes?How to remove last n characters from every element in the R vectorChanging every element in vector or list by the same numberHow to implement a dispose pattern into a reference class in R?













0















I am trying to convert every object in my vector of strings to a reference class. Suppose my reference class is:



myrefclass <- function(str) 
methods <- list()

methods$cnt <- function()
return(str_length(str))


methods



I tried to convert the following vectors (albeit, no success):



v1 <- c("ABC", "D", "FGHI")
v2 <- c(ABC="ABC", D="D", FGHI="FGHI")


Then I try to apply the reference class to each element of the vector:



res1 <- sapply(v1, myrefclass)
res2 <- sapply(v2, myrefclass)


I would then think I could use this as follows (but regretfully it doesn't work):



> res1["ABC"]$cnt
NULL
> res2["ABC"]$cnt
NULL


How do I create a vector of reference classes and access its methods?




NOTE #1: I would prefer a base-R solution but it would be interesting to
see what packages might help



NOTE #2: I am looking for a dynamic solution. To illustrate that point,
suppose an extension of this question would be to use res1 or res2
to find all strings that have $cnt=3. Therefore, accessing strings
as in res1$ABC$cnt won't work as you don't know that ABC is in
v1 or v2 (whichever you think is appropriate).











share|improve this question
























  • If you want the number of characters, use nchar.

    – yarnabrina
    2 days ago











  • For clarification, you want res1["ABC"]$cnt=3 and res1["FGHI"]$cnt=4. Is that it?

    – yarnabrina
    2 days ago











  • yes, that's exactly what I would like to achieve

    – Denis
    2 days ago















0















I am trying to convert every object in my vector of strings to a reference class. Suppose my reference class is:



myrefclass <- function(str) 
methods <- list()

methods$cnt <- function()
return(str_length(str))


methods



I tried to convert the following vectors (albeit, no success):



v1 <- c("ABC", "D", "FGHI")
v2 <- c(ABC="ABC", D="D", FGHI="FGHI")


Then I try to apply the reference class to each element of the vector:



res1 <- sapply(v1, myrefclass)
res2 <- sapply(v2, myrefclass)


I would then think I could use this as follows (but regretfully it doesn't work):



> res1["ABC"]$cnt
NULL
> res2["ABC"]$cnt
NULL


How do I create a vector of reference classes and access its methods?




NOTE #1: I would prefer a base-R solution but it would be interesting to
see what packages might help



NOTE #2: I am looking for a dynamic solution. To illustrate that point,
suppose an extension of this question would be to use res1 or res2
to find all strings that have $cnt=3. Therefore, accessing strings
as in res1$ABC$cnt won't work as you don't know that ABC is in
v1 or v2 (whichever you think is appropriate).











share|improve this question
























  • If you want the number of characters, use nchar.

    – yarnabrina
    2 days ago











  • For clarification, you want res1["ABC"]$cnt=3 and res1["FGHI"]$cnt=4. Is that it?

    – yarnabrina
    2 days ago











  • yes, that's exactly what I would like to achieve

    – Denis
    2 days ago













0












0








0








I am trying to convert every object in my vector of strings to a reference class. Suppose my reference class is:



myrefclass <- function(str) 
methods <- list()

methods$cnt <- function()
return(str_length(str))


methods



I tried to convert the following vectors (albeit, no success):



v1 <- c("ABC", "D", "FGHI")
v2 <- c(ABC="ABC", D="D", FGHI="FGHI")


Then I try to apply the reference class to each element of the vector:



res1 <- sapply(v1, myrefclass)
res2 <- sapply(v2, myrefclass)


I would then think I could use this as follows (but regretfully it doesn't work):



> res1["ABC"]$cnt
NULL
> res2["ABC"]$cnt
NULL


How do I create a vector of reference classes and access its methods?




NOTE #1: I would prefer a base-R solution but it would be interesting to
see what packages might help



NOTE #2: I am looking for a dynamic solution. To illustrate that point,
suppose an extension of this question would be to use res1 or res2
to find all strings that have $cnt=3. Therefore, accessing strings
as in res1$ABC$cnt won't work as you don't know that ABC is in
v1 or v2 (whichever you think is appropriate).











share|improve this question
















I am trying to convert every object in my vector of strings to a reference class. Suppose my reference class is:



myrefclass <- function(str) 
methods <- list()

methods$cnt <- function()
return(str_length(str))


methods



I tried to convert the following vectors (albeit, no success):



v1 <- c("ABC", "D", "FGHI")
v2 <- c(ABC="ABC", D="D", FGHI="FGHI")


Then I try to apply the reference class to each element of the vector:



res1 <- sapply(v1, myrefclass)
res2 <- sapply(v2, myrefclass)


I would then think I could use this as follows (but regretfully it doesn't work):



> res1["ABC"]$cnt
NULL
> res2["ABC"]$cnt
NULL


How do I create a vector of reference classes and access its methods?




NOTE #1: I would prefer a base-R solution but it would be interesting to
see what packages might help



NOTE #2: I am looking for a dynamic solution. To illustrate that point,
suppose an extension of this question would be to use res1 or res2
to find all strings that have $cnt=3. Therefore, accessing strings
as in res1$ABC$cnt won't work as you don't know that ABC is in
v1 or v2 (whichever you think is appropriate).








r






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago







Denis

















asked 2 days ago









DenisDenis

5,873957118




5,873957118












  • If you want the number of characters, use nchar.

    – yarnabrina
    2 days ago











  • For clarification, you want res1["ABC"]$cnt=3 and res1["FGHI"]$cnt=4. Is that it?

    – yarnabrina
    2 days ago











  • yes, that's exactly what I would like to achieve

    – Denis
    2 days ago

















  • If you want the number of characters, use nchar.

    – yarnabrina
    2 days ago











  • For clarification, you want res1["ABC"]$cnt=3 and res1["FGHI"]$cnt=4. Is that it?

    – yarnabrina
    2 days ago











  • yes, that's exactly what I would like to achieve

    – Denis
    2 days ago
















If you want the number of characters, use nchar.

– yarnabrina
2 days ago





If you want the number of characters, use nchar.

– yarnabrina
2 days ago













For clarification, you want res1["ABC"]$cnt=3 and res1["FGHI"]$cnt=4. Is that it?

– yarnabrina
2 days ago





For clarification, you want res1["ABC"]$cnt=3 and res1["FGHI"]$cnt=4. Is that it?

– yarnabrina
2 days ago













yes, that's exactly what I would like to achieve

– Denis
2 days ago





yes, that's exactly what I would like to achieve

– Denis
2 days ago












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280695%2fhow-do-i-change-every-element-in-a-vector-to-my-reference-class%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280695%2fhow-do-i-change-every-element-in-a-vector-to-my-reference-class%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현