How can I select text from a row and column of a data frame without returning all Levels in R? [duplicate]

StackOverflow https://stackoverflow.com/questions/13732224

  •  05-12-2021
  •  | 
  •  

Question

Possible Duplicate:
dropping factor levels in a subsetted data frame in R

I would like to get the text from a cell in a data frame (and use that text to create a file). However, whenever I select a specific row and column from the data frame, the result is the contents of the data frame followed by a list of levels from the data frame. For example:

getFileNameTest<-function(
   columnNames=c(cName1,cName2)
)
{
list1<-c("joe", "bob", "sue")
list2<-c("jones","smith","smith")
myDataFrame<-data.frame(list1,list2)

joeFileName<-myDataFrame[1,1]
return(joeFileName)

}

This function returns:

[1] joe
Levels: bob joe sue

But I would like just "joe" so that I can later create a file named "joe." How do I grab the contents of a specific row and column in a data frame without returning the levels?

Was it helpful?

Solution

as @joran suggests or:

df <- data.frame(x=sample(LETTERS,10))
df[,1][[1]]

as.character(df[,1][[1]])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top